jQuery in Action, 3rd edition
The moose likes JSP and the fly likes Prepopulating a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Prepopulating a jsp" Watch "Prepopulating a jsp" New topic

Prepopulating a jsp

santu Naid

Joined: Jan 06, 2008
Posts: 11
I have a jsp page which has many fields like text, textarea, drop down, radio button,
First the user enters all the values into this page and goes to some other page, and in this way he continues,but there is a link in on of the pages which brings him back to the first page. when he comes to this page all the filds should be prepopulated.

I made a session, in which i saved all the entered data, and when i come to the first page i am able to get the entered data.And i am able to prepopulate the text fields using value=<%=entereddata%>, but how can i prepopulate a drop down, i mean have a drop down in a selected state
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

By adding selected or 'selected="selected" to an option, you can let the browser know that a particular entry has been selected.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
santu Naid

Joined: Jan 06, 2008
Posts: 11
The options to be selected is not constant, it changes every now and then,

When a user selects an option, and then leaves the page to go to a new page,
and when he returns to same page again, the drop down should be in a selected state, the same option which he selected before.

while run time...
When i come to this page i have the value of the selected option from the session object , with this value how can i make the drop down to be in selected state with that value dynamically.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Typically it would look something like this:

There are less verbose ways of doing this but I think this is the most explanatory.
[ January 07, 2008: Message edited by: Gregg Bolinger ]

GenRocket - Experts at Building Test Data
I agree. Here's the link: http://aspose.com/file-tools
subject: Prepopulating a jsp
It's not a secret anymore!