473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 13383
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

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

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
5
by: SA SA | last post by:
Is this possible? I have three items in drop down "Select Payment Type", "Credit Card" and "Check". if user select Credit card then i need to post the form variables to different URL than check...
4
by: Rohit111111 | last post by:
Hello all, I am new to this forum ans also i am new to asp.net, I have a problem in validating a dropdown list for a blank value please help
1
by: shiva srivastava | last post by:
can i select more than one option in DropDownList? if yes then what is the code for this in vb.net? plz reply.
5
parshupooja
by: parshupooja | last post by:
Hello, I am using asp.net C# I have a form which has various controls such as Dropdownlist, textboxes. If user select value"10" or "13' from drop down than textbox field should become mandatory,...
3
by: jmash | last post by:
Hello, The requirement is to display rows of data on a classic ASP page for rows in a recordset. On each row we have a link at the end to show detailed information about the selected row. A...
4
by: semomaniz | last post by:
I have a list box that has a list of roles defined. List of roles are binded to the list box in page load event. I am trying to retrieve the selected role from the text box but i am getting a null...
1
by: AarthiVedhavalli | last post by:
Hi, In my C# web application I have a list box whic is binded to database. What i need now is , if i double click a value in list box that vale should be added to a dropdown list.. Any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.