• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP form forwarding select data to servlet?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
     
    Bartender
    Posts: 1845
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.)
     
    reply
      Bookmark Topic Watch Topic
    • New Topic