0

This is my coding for order.jsp, a form for customer to insert order and I use session.menus to display option menu in a HTML input element from database. I already connect to database using jdbcutility.java, where I put sql statement to connect my servlet with database and its working for login but not for this session.

<form class="form-horizontal" method="post" action="InsertOrderServlet">


<center>
    <table border="10" cellpadding="20" cellspacing="20">
        <thead>
            <tr>
                <th colspan="2"><h2 style="line-height: 3;" >Order Food</h2></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><br><br>Food</br></br></td>
                <td>
                    <br><br>
                    <div class="col-lg-9">
                        <select class="form-control" name="menuName">
                            <c:forEach items="${sessionScope.menus}" var="currentmenu" varStatus="loop">
                                <option><c:out value="${currentmenu.foodName}" /></option>
                            </c:forEach>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td>Quantity</td>
                <td><input type="text" name="quantity" required/></td>
            </tr>
            <tr style="line-height: 10;" >

                    <td> <button  class="btn btn-primary" type="reset" >Cancel</button></td>
               <td > <button type="submit" class="btn bt primary">Submit</button></td>

                </td>                        
           </tr> 

        </tbody>

    </table>
    </center>
</form>

getMenuServlet.java

  //select all from menu
    try {                    
        ResultSet rs = jdbcUtility.getPSSelectMenu().executeQuery();

        while (rs.next()) {       

            menu = new Menu();
            menu.setId(rs.getInt("menuid"));
            menu.setfoodName(rs.getString("foodName"));
            menu.setImage(rs.getString("image"));           
            menu.setPrice(rs.getDouble("price"));

            //put into arraylist
            menus.add(menu);
        }
    }
    catch (SQLException ex) 
    {            
    }               

    //put into sessions
    session.setAttribute("menus", menus);

jdbcutility.java

 String sqlValidateLogin = "Select username,password from customer where username=? and password=?";
        psInsertLogin = con.prepareStatement(sqlValidateLogin);

        String sqlInsertOrder = "INSERT INTO orderfood(menuName, quantity) " + "VALUES(?, ?)";
        psInsertOrder = con.prepareStatement(sqlInsertOrder);

        String sqlSelectAllMenu ="SELECT * FROM menu";   
        psSelectAllMenu = con.prepareStatement(sqlSelectAllMenu);

        String sqlSelectAllOrder ="SELECT * FROM orderfood";   
        psSelectAllOrder = con.prepareStatement(sqlSelectAllOrder);

This keep occurring, how do I fix this?

image blank

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Make sure the JSP is allow access session.

<%@ page session="true" %>

To use core JSTL, make sure the following code is included.

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Jairo Cordero
  • 640
  • 6
  • 8