469,356 Members | 1,957 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Problem in maintaining the selected value of dropdown list

Hi,

i have one jsp in which i select a value from drop down and on change of this a servlet is called that accesses some values and return to the same jsp where these values get populated in another dropdown list . Now the problem is when the jsp loads again (after fetching the values in servlet) the selected value of dropdown is lost. How can i make it happen that when the page reloads thedrop down list show me the previous selected value and below that another values.

Thanks
Oct 29 '07 #1
6 12993
r035198x
13,262 8TB
Hi,

i have one jsp in which i select a value from drop down and on change of this a servlet is called that accesses some values and return to the same jsp where these values get populated in another dropdown list . Now the problem is when the jsp loads again (after fetching the values in servlet) the selected value of dropdown is lost. How can i make it happen that when the page reloads thedrop down list show me the previous selected value and below that another values.

Thanks
You pass the previosly selected value back to the JSP and use a simple if condition

Expand|Select|Wrap|Line Numbers
  1. <%
  2. if(value.equals("previousValue")) {
  3. %> 
  4. <OPTION value ="<%=value%>" selected><%=value%>  
Oct 29 '07 #2
You pass the previosly selected value back to the JSP and use a simple if condition

Expand|Select|Wrap|Line Numbers
  1. <%
  2. if(value.equals("previousValue")) {
  3. %> 
  4. <OPTION value ="<%=value%>" selected><%=value%>  
Hi,

Thanks for ur reply.

But in this case i will get duplicate items in same dropdown list i.e. One due to if condition and other due to static options.
Oct 29 '07 #3
r035198x
13,262 8TB
Hi,

Thanks for ur reply.

But in this case i will get duplicate items in same dropdown list i.e. One due to if condition and other due to static options.
You should use a loop to populate the other "static" options. Put them in an array and populate them from the array.
Oct 29 '07 #4
Hi,

Thanks for your valuable suggestion. I think this will get solved now.

I want to ask one more thing.
Is it possible that we use
Expand|Select|Wrap|Line Numbers
  1. HttpSession session=request.getSession(true)
  2. session.setAttribute("str",str);
and
Expand|Select|Wrap|Line Numbers
  1. request.setAttribute("str1",str1);
and then use RequestDispatcher and forward to pass the request in same servlet.

Thnax
Oct 29 '07 #5
r035198x
13,262 8TB
Hi,

Thanks for your valuable suggestion. I think this will get solved now.

I want to ask one more thing.
Is it possible that we use
Expand|Select|Wrap|Line Numbers
  1. HttpSession session=request.getSession(true)
  2. session.setAttribute("str",str);
and
Expand|Select|Wrap|Line Numbers
  1. request.setAttribute("str1",str1);
and then use RequestDispatcher and forward to pass the request in same servlet.

Thnax
Should work but normally you want to use one and not both methods.
Use the session to store attributes that belong to a session and use request.setAttribute when you want to pass a value from a servlet to JSP. You'd then use requestDispatcher with include(request, response)
Oct 29 '07 #6
session["value"]!=null
{
//bind ur code
}
Jul 15 '15 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.