0

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!

4
  • 1
    The ${tempID} should work. The getParameter("tempID") obviously don't work as you've set it as a request attribute which should be obtained by getAttribute("tempID"). How exactly does ${tempID} fail for you? Does EL in general work in your environment or not? Commented Apr 24, 2013 at 12:42
  • Thanks! False ideas about attribute/parameter. It's true that I can't seem to print values on jsp with EL. It doesn't show at all. Commented Apr 24, 2013 at 13:10
  • Then you've another rather major problem: EL doesn't work at all. I say, "rather major", because this way you would be forced to use decade-old scriptlet techiniques which is officially discouraged since JSP 2.0 in 2003. I strongly recommend to fix your project in order to get EL to work to avoid from being sucked into a downward spiral. Perhaps you copypasted a wrong web.xml example from elsewhere? Or perhaps you littered the /WEB-INF/lib with wrong JARs? Commented Apr 24, 2013 at 13:16
  • All in my web.xml file I've written myself except what Netbeans generated. I'll have to check out the JARs (although I didn't manually add to those either). Thanks for the pointer! Commented Apr 24, 2013 at 15:36

1 Answer 1

1

try this

<%= request.getAttribute("tempID") %> 

Because you set variable as attribute

 request.setAttribute("tempID",tempID); 
Sign up to request clarification or add additional context in comments.

1 Comment

It works!! I can't believe I didn't try this. I was under the assumption that Parameter was just the value of the attribute. Thanks a bunch!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.