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!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2315422
  • 3
  • 1
  • 2
  • 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? – BalusC Apr 24 '13 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. – user2315422 Apr 24 '13 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](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202) 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? – BalusC Apr 24 '13 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! – user2315422 Apr 24 '13 at 15:36

1 Answers1

1

try this

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

Because you set variable as attribute

  request.setAttribute("tempID",tempID);
samba
  • 2,263
  • 2
  • 13
  • 13
  • 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! – user2315422 Apr 24 '13 at 13:05