Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

saving an input element state(value)

 
moshik salem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi,

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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi ,

Normally what i used to do is

page1.jsp

some javascript code to submit to "MyServlet"
......
<form>
name
<%
String var1=request.getParameter("uid");
if(var1==null)
var1="";

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

%>
</form>

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


If still problem not slove post the demo code
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
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).
 
    Bookmark Topic Watch Topic
  • New Topic