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 ]
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.
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.