]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Handle redirect in filter to get rid of scriptlet
authorRoland Haeder <roland@mxchange.org>
Mon, 31 Aug 2015 12:13:01 +0000 (14:13 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 31 Aug 2015 12:13:01 +0000 (14:13 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java
web/form_handler/add_item.jsp

index 2df040c874b16c7609ad39d348b744952701ace5..6de8edc808fc2ba346aaeaa27c857a7c5081e805 100644 (file)
@@ -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);
index 582596c818e54471c71c65a6c0cae96d43d7f25a..f17e02589535c8ca23b4bd90f0c1e3821c0dbbe5 100644 (file)
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <c:set var="basePath" value="${pageContext.request.contextPath}" />
 
-<%
-       // 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");
-       }
-%>
-
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
        <head>