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

Problem retreiving the value of select option

 
Saumyaraj Zala
Ranch Hand
Posts: 56
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a select tag in my form which is to be send to Servlet. I have made the contents of the select tag dynamic(it gets values from a table column in DB).
('r' is ResultSet)
My problem is how can i send the value the user has selected from select tag to servlet. For using Request.getparameter("name") I must know the value of option tag.
I my confused.Please help..
Thanks.
 
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
Just like any other HTML page, the value of the submitted parameter for the select element will be the value of the selected option.
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as @Bear said just call request.getParameter("name").
 
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
Of course, you've got to give your select element a name.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever there's a need to fetch the submitted values to the Servlet ...
always make sure to name the HTML elements whose values are required.

then using


you can easily get the entered value or in your case the selected value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic