From 5610918215f4ea2e5f1bfb79dbf9fb0e5dbca816 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 31 Aug 2015 14:13:01 +0200 Subject: [PATCH] =?utf8?q?Handle=20redirect=20in=20filter=20to=20get=20rid?= =?utf8?q?=20of=20scriptlet=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../servlet/basket/BasketItemAddedFilter.java | 15 ++++++++++++++- web/form_handler/add_item.jsp | 17 ----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java index 2df040c8..6de8edc8 100644 --- a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java +++ b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java @@ -26,6 +26,7 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; @@ -84,8 +85,11 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { this.getLogger().debug(MessageFormat.format("item.id={0},item.itemId={1},item.itemType={2},item.amount={3}", item.getId(), item.getItemId(), item.getItemType(), item.getAmount())); //NOI18N try { + // Cast to servlet request + HttpServletRequest servletRequest = (HttpServletRequest) request; + // Get session instance - HttpSession session = ((HttpServletRequest) request).getSession(); + HttpSession session = servletRequest.getSession(); // Debug message this.getLogger().debug(MessageFormat.format("session={0}", session)); //NOI18N @@ -128,6 +132,15 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { // Register item with it basket.addItem(item); + + // Is amount null or zero? + if ((item.getAmount() == null) || (item.getAmount() == 0)) { + // Then redirect to added=0 + ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=0"); //NOI18N + } else { + // Redirect to proper URL + ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=1"); //NOI18N + } } catch (final SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new ServletException(ex); diff --git a/web/form_handler/add_item.jsp b/web/form_handler/add_item.jsp index 582596c8..f17e0258 100644 --- a/web/form_handler/add_item.jsp +++ b/web/form_handler/add_item.jsp @@ -27,23 +27,6 @@ <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<% - // Get amount from item - Long amount = item.getAmount(); - - // Debug message - BaseFrameworkSystem.getInstance().getLogger().debug("amount=" + amount); - - // Is amount null or zero? - if ((null == amount) || (amount == 0)) { - // Then redirect to added=0 - response.sendRedirect(request.getContextPath() + "/?add=0"); - } else { - // Redirect to proper URL - response.sendRedirect(request.getContextPath() + "/?add=1"); - } -%> - -- 2.39.5