Retain the values in dropdown

I have a drop down of state list and needs to remeber the selected value once page reloaded. it is in JSP and Struts .
mgoutham22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JavatmCommented:
make hidden textfield then on page reload pass the value to the hidden textfield in that way you retain the value from the list.
0
JavatmCommented:
Here's a sweet demo (by default the result is null until you select a value and submit) :

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <h1>Retain Demo</h1><br>
    <form method="post" action="demo.jsp">
    <select name="List" class="style5" style="border:thin; background:#6AB5FF; color:#FFFFFF">
                      <option value="CheeseBurger" selected>CheeseBurger</option>
                      <option value="HamBurger">HamBurger</option>
                      <option value="DoubleCheeseBurger">DoubleCheeseBurger</option>
    </select>
    <% String user1 = request.getParameter("List"); %>
    <br><br><input type="hidden" name="hdf1" value="<%=user1%>">
    Value of hidden field is : <% out.println("" + user1); %>
    <br><br><input type="submit" value="submit">
    </form>    
    </body>
</html>
0
fargoCommented:
One other way is to keep the action form in session scope and it will then retain the last state [this will avoid any hidden field handling]
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

fargoCommented:
In struts-config.xml, for a particular action

<action
       path="/showPage"
       type="com..xx.whateverAction"
       scope="session"
       name="pageForm"
       validate="false">
         <forward
          name="success"
          path="/pages/whateverPage.jsp" />
    </action>

scope is defined to session here.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mgoutham22Author Commented:
I am sorry but that did not work for me . any other tips , i clicked on accept with out testing .

0
fargoCommented:
do u have a reset method in the actionForm? if yes, remove it. You need to restart the tomcat after the struts-config change. You can very well reopen the question.
0
mgoutham22Author Commented:
no reset method , i did restart weblogic after change.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.