Results 1 to 4 of 4
  1. #1
    system32 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Question Why wont my JSP page display my selected item?

    I am new to JSP and for learning I am trying to create a cart application. A user is presented with a list of items they may reserve and when they hit the reserve link they are brought to a page where it shows the book they selected. My code does not show this book but an empty screen when I select reserve. This is my cart servlet:
    Java Code:
                String action = request.getParameter("action");
    
                HttpSession session = request.getSession();
                ECart cart = (ECart) session.getAttribute("cart");
                if (cart == null)
                    cart = new ECart();
    
                if (action.equals("reserve"))
                {
                   String productCode = request.getParameter("code");
                   Book book = ELoan.getItem(productCode);
                   cart.addItem(book);
                   ELoan.subtractFromQOH(productCode, 1);
                   session.setAttribute("cart", cart);
                }            
    
                String url = "/AKJHCart.jsp";
                RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
                dispatcher.forward(request, response);
    This is my JSP where I want to display the cart item:
    Java Code:
        <body>
            <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
            <c:forEach var="item" items="${cart}">
            <table border="1">
                <tr>
                    <td>Code</td>
                    <td>Description</td>
                    <td>Quantity</td>
                </tr>
                <tr>
                    <td>${item.code}</td>
                    <td></td>
                    <td></td>
                </tr>
            </c:forEach>
            </table>
        </body>
    Thanks for any help

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    1.)Check your server logs to see the exception that got generated. The exception trace gives you a clue as to what the problem is and without it everyone is just guessing.
    2.) In your JSP page, where have you declared ${cart}? If cart is in session scope then you access it using
    Java Code:
     ${sessionScope.cart}
    not just ${cart}.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,930
    Rep Power
    22

    Default

    Can I just say that it is nice to actually see JSPs and servlets being used correctly for a change?

  4. #4
    system32 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    Found my error. Was redirecting to the JSP page and not the servlet. Simple mistake. Thanks for the help :)

Similar Threads

  1. wont display selected array
    By newbie80 in forum New To Java
    Replies: 7
    Last Post: 03-21-2011, 02:10 AM
  2. Replies: 4
    Last Post: 12-11-2010, 06:08 PM
  3. how to display image selected by JFileChooser
    By khushi.cutegal in forum AWT / Swing
    Replies: 17
    Last Post: 07-24-2010, 06:03 AM
  4. Selecting last item from a Jcombobox wont work
    By cotarelo in forum AWT / Swing
    Replies: 1
    Last Post: 07-13-2010, 11:30 PM
  5. How to get the selected item from combox
    By man4ish in forum AWT / Swing
    Replies: 5
    Last Post: 12-30-2009, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •