Hi all,
I want some inputs from you on the following issue.

I have two drop downs on a jsp page.On the selection of the first drop down the page will get refreshed and the second combo box will be loaded regarding the selection of the first drop down.
Now, everything is going fine except when the page get refreshed after selecting the first combo box the selected option of the first combo box is lost and changed to the default selected option "Please select".
All I want to know is that how can I maintain session to retain the selected option of the first combo box after the page gets refreshed.

Hi Koushik,

Below code is to set the session

//This code goes in server side (servlet).

HttpSession session = request.getSession(true); //create a session object
 session.setAttribute("key", "value");

//This code goes in client side (jsp).

// this will return the value in session
 String value=(String) session.getAttribute("key");

After getting the session value set it to first combo box in onLoad intself

we can also use the ajax to solve ur problem.

Hi Koushik,

Below code is to set the session

//This code goes in server side (servlet).

HttpSession session = request.getSession(true); //create a session object
 session.setAttribute("key", "value");

//This code goes in client side (jsp).

// this will return the value in session
 String value=(String) session.getAttribute("key");

After getting the session value set it to first combo box in onLoad intself

we can also use the ajax to solve ur problem.

That is not the right way to use session. You shouldn't be putting things in the session for a simple submit or refresh page.

koushikroy1989, I assume that you submit the value of the first drop down list and then you load values to the second. If so, when you "send" the data of the second drop down list you can also send the value of the first drop down list and have that value selected.

Post some code so we can see how you send the data and how you load the second drop down list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.