I'm trying to retrieve a selected value from a .jsp in a servlet. The values displayed in the option are from ArrayList of "Item" objects (with variables ID, name, descript, price, quant).
in itemsCatalog.jsp (partial):
<form name="f1" action="ControllerServlet" method="GET"> <select name="itemSelect"> <c:forEach items="${list}" var="entry"> <option value="${entry.ID}">${entry.name}</option> </c:forEach> </select> <br><input type="hidden" name="DETAILS" value="new"/> <br><input type="submit" name="Submit" value="Show Details"/> </form>
In ControllerServlet I've tried to access the selected option with:
String tempID = request.getParameter("itemSelect"); request.setAttribute("tempID",tempID); request.getRequestDispatcher("itemDetails.jsp").forward(request,response); However, when I try to access it on itemDetails.jsp with
<%= request.getParameter("tempID") %> or
${tempID} Then I receive a null value. If I try to directly access the original "itemSelect" parameter on itemDetails.jsp, then I receive the correct String.
Here's my question: why is the servlet not receiving this parameter, and what can I do to fix it? Receiving parameters from text boxes works.
(Note, I am currently just trying to retrieve the String value before I keep processing.)
In case it helps, I'm using Netbeans 7.3, and Glassfish 3.2.1, on Vista. Thanks for any help!
${tempID}should work. ThegetParameter("tempID")obviously don't work as you've set it as a request attribute which should be obtained bygetAttribute("tempID"). How exactly does${tempID}fail for you? Does EL in general work in your environment or not?web.xmlexample from elsewhere? Or perhaps you littered the/WEB-INF/libwith wrong JARs?