From: Roland Haeder Date: Mon, 31 Aug 2015 12:13:01 +0000 (+0200) Subject: Handle redirect in filter to get rid of scriptlet X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5610918215f4ea2e5f1bfb79dbf9fb0e5dbca816;p=pizzaservice-war.git Handle redirect in filter to get rid of scriptlet Signed-off-by:Roland Häder --- 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"); - } -%> -