473,395 Members | 2,006 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,395 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 13390
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.