• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP form forwarding select data to servlet?

 
Charles Wells Iii
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to JSP and Servlets and I am trying to figure out why I am unable to retrieve data from a request object when passed in a form. My JSP has script-lets that I use to dynamically populate a drop down box. This piece appears to be working. I have a simple servlet that I am using to verify that the select value is passed along and it is not. I just appears as a blank space. Anyone have any ideas? Below is some of the code that I'm using.

JSP:



Servlet:


I can provide the listDir code but it's just returning the contents of a directory. This piece also appears to be working as my drop down list IS populated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Java scriptlets are obsolete and have been for 15 years. 15 years. They should not be used in any JSP written after 2001.

You should be using the JSTL and EL and modern JSP.

I recommend newcomers to JSP and servlets read these articles:
  • The Secret Life of JSPs
  • The Front Man


  • Do the option values get properly declared in the generated HTML?
     
    Stefan Evans
    Bartender
    Posts: 1784
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Any reason you used a <%= expr %> tag to print the name between the option tags, and a <% scriptlet %> tag to print it for the value attribute?


    I would echo Bear's comments about java code in a jsp.
    Heck, you could probably even convert it straight over to JSTL/EL:

     
    Charles Wells Iii
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the response. I will look over the documentation provided in the links. As for why I used both an expression and a scriptlet, I found I needed the scriptlet to populate the values in the drop-down box and the expression to actually see those values in a browser. Without both I would get an empty drop-down. A debugger would show me the values were populating, I just couldn't see them in a browser. I'll convert using the core taglib and see if I can forward the selected value to my servlet.

    Thanks again for all the information provided.
     
    Paul Clapham
    Sheriff
    Posts: 21416
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The other piece of advice usually given to people who ask this sort of question: look at the HTML which your JSP generates. Is it what you meant to generate? (Your browser has a way to do that.)
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic