This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null request parameter from Select/Option element

 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove this from your form attribute and then try
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the multi-part form? That will prevent normal parsing of the request.
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic