This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Null request parameter from Select/Option element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Null request parameter from Select/Option element" Watch "Null request parameter from Select/Option element" New topic
Author

Null request parameter from Select/Option element

Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
I have successfully coded almost exactly the same thing and have it working; but I've been looking at this one several hours and just cannot determine my mistake or lack of understanding.

In the JSP, I have:



PAPERTITLE is the name of the column in the database and does display correctly in the JSP so I know the data is being retrieved correctly from the database.

The value is just not getting to the servlet through the Request object or so it seems.

This is how I ask for the value from the Select /Option element in the servlet:


I apologize for using old fashioned scriplets. I've just recently added logging to this project and version control. JSTL and EL are on my list; but here is only so much time in the day.

Thanks ; I hope someone can see what I am obviously overlooking. I keep thinking I understand how all this works; but if I did, it would work.




Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575



This is how I ask for the value from the Select /Option element in the servlet:

String paperTitle = req.getParameter("paper");



This is Correct. and Please tell the error what you get ? what you get the value for paperTitle in servlet. Simply saying "not working " wont help us to answare .

Note: see the view source of your jsp
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816



Seems like you are setting a attribute of type ResultSet somewhere? You could have use some other data structure instead .

Are you submitting from within the <form> tag in the jsp?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
The user is selecting the value within a jsp form tag and then using a Submit button. So I would assume, as in my other working example, that this would also work; but the value is null in the servlet submitted to from the Action tag of the form.
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
The ResultSet if from a database query in a servlet. The values are in the ResultSet as they are displayed in the Select/Option element of the jsp. The selected value is not available after the Submit button sends the form to the next servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

How the <select> element gets built is completely moot.

Inspect the HTML that's sent to the browser to make sure that it's valid and that the elements are well-formed. Also be sure that the select element is a descendant of the form which is being submitted.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
Here's the complete html for the jsp submitting to the servlet; when the servlet asks for the value from the select element, it is null.




Here's the servlet request for the value:


Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

remove this from your form attribute and then try
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

Why the multi-part form? That will prevent normal parsing of the request.
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
I thought I had to use the multi-part form parameter when working with files; but I realize now I'm not doing that yet in this form.
I'm just using the name of the file at this point. Thanks so much for taking such a close look at the problem.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60738
    
  65

You will only need a multi-part form when doing a file upload. Any other form should not change the default enctype.

(And when/if you get to file uploading, you'll need to parse the request yourself -- or use a 3rd party tool to do it. See the FAQs.)
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
What does the multipart form parameter actually do to the envelope? I felt like this had to be something I didn't know about the big picture. So glad we kept at it until I did understand it. I will be learning JSTL and El, but I think this has been a valuable learning experience also.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null request parameter from Select/Option element
 
Similar Threads
Problem creating a PreparedStatement
Struts html:radio Question
Populating a html select tag without scripting
&nbsp; ...
Problem filling Select from Database - c:forEach