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 Drop down population Issue. 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 "Drop down population Issue." Watch "Drop down population Issue." New topic

Drop down population Issue.

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Folks,
Im developing a jsp page where I set the value obtained from a dropdown to insert into a database.
Im using java script to fetch the value of the dropdown in the jsp , and then use the value for processing in the servlet. Im able to pass the value of the dropdown successfully here .
Its something like this..

However , when I click on a value in the dropdown the page submits as expected and the form is submitted to the Servlet , which processes the request,but when the page reloads after submission the dropdown value is lost and is set to the default "--Select--" value , any ideas where i could be going wrong ?

Learning and Learning!-- Java all the way!
Gopinath Periasamy Nachimuthu

Joined: May 23, 2011
Posts: 1

Dear Vic Hood,
Once the page is submited, the response is commited. When the page reloads after submission the request is new request hence the value whichever you set before submit will not be available. If you need to maintain the value you had assigned to the 'd-down' drop down you need to set the value to the 'd-down' attribute in the servlet and get the value form the request attribute in jsp and set that value to the 'd-down'
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60740

You need to put the selected attribute on the <option> that you wish to be selected. Otherwise it defaults to the first choice.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bang on target,Bear!
Thanks a lot
It is sorta covered in the JavaRanch Style Guide.
subject: Drop down population Issue.
Similar Threads
Page submission on change of drop down value not working
Retaining drop down values on page submit
Comparing values using JSTL
Dropdown Selected returning unexpected value on submit.
Checkbox value not being passed to bean.