aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

saving an input element state(value)

moshik salem
Greenhorn

Joined: Dec 06, 2011
Posts: 10
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

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
Greenhorn

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
Greenhorn

Joined: Feb 05, 2011
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: saving an input element state(value)