File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Value of control not preserved Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Value of control not preserved" Watch "Value of control not preserved" New topic

Value of control not preserved

Kumar Navin
Ranch Hand

Joined: May 27, 2004
Posts: 52
Hi! Friends,
My problem is as such:- Have a JSP page, a.jsp(say) which is invoked through a servlet b.class(say). On page a.jsp I have a combo box which is populated by values fetched from database. This page has got hyperlinks which invokes the servlet b.class and in turn transfers the control to a.jsp, which displays to the user. I want the value of the combo to be remain the same as selected by the user when the page is displayed for the second time but am not able to do so.
Can anyone help me out. Urgently req. else am thrown out.
[ January 16, 2005: Message edited by: Bear Bibeault ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You could either:
Have the servlet put the selected value in a request scoped variable that the JSP reads and uses to test against the values in the select box options -- addting ' selected ' if true.

you could build the selectbox options in whatever bean/servlet is gathering the list from the database in the first place and add the ' selected ' attribute there. Then, pass the option tags via a request scoped variable to the JSP.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mike Ottinger
Ranch Hand

Joined: Jan 11, 2002
Posts: 125
Hi Kumar,

I had to do something like this recently. I basically did Ben's second option. Based on a request variable I built the combobox by using a custom tag to generate the html. To avoid creating a custom tag, you could simply have your servlet call a class within your app that returns to you the html-encoded form as a string.

SCJP 1.4 SCJD 1.5
jQuery in Action, 3rd edition
subject: Value of control not preserved
It's not a secret anymore!