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

Value of control not preserved

 
Kumar Navin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks....
-Navin.
[ January 16, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Or:
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.
 
Mike Ottinger
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic