File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes saving an input element state(value) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic

saving an input element state(value)

moshik salem

Joined: Dec 06, 2011
Posts: 10

i wrote a jsp file which has a form and some input elements, after a form submitting to servlet, the servlet forward back to the jsp but the input elements does

not keep their values has it were before submitting. my question is how to keep the values of the input elements like they were before the submitting?
duy nguyen H

Joined: Aug 30, 2011
Posts: 11
If your servlet just returns to jsp file simply, you can use <%= request.getParameter("name") %> or one different option is save variables' values into session object and get them from session object in jsp page.
moshik salem

Joined: Dec 06, 2011
Posts: 10
i am trying to post a form to the servlet using javascript, the servlet is forwards back to the same jsp. but because the javascript the form is submitted again

and the same servlet is forwards back again, and this process occur over and over again.

i tried to stop this behavior with hidden field that acts like a flag but his value is lost after the servlet forwards back.

what to do to solve this problem?
honey sachdeva

Joined: Feb 05, 2011
Posts: 6
Hi ,

Normally what i used to do is


some javascript code to submit to "MyServlet"
String var1=request.getParameter("uid");

out.println("<input type=text value="+var1+" name=uid>");


considering that servlet forward like this
RequestDispacther rd = request.getRequestDispatcher("page1.jsp");

If still problem not slove post the demo code
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

Sounds a lot like your other post where things aren't working as they should be. Your script must be dining something rather hanky, but you haven't posted it in wither topic.

I'm going to close this topic so we can concentrate on the other one where you should post your script (be sure to UseCodeTags).

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: saving an input element state(value)
It's not a secret anymore!