(unknown)

Zerbe John W <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <[email protected]>
generally speaking, you can use the requestDispatcher to forward to a jsp which "is" your input form. This jsp can use all of the request attributes and request parameters to "prefill" the fields with the "value=" attribute on your <input> tags. 
eg: 
in your servlet:
 
boolean tryAgain = false;
String attrName = "myinputfield";
String attrVal = request.getParameter(attrName);
if (attrVal != null) {
    if ( fieldValidator(attrName,attrVal).isGoofy()){
        tryAgain = true;
        request.setAttribute(attrName,"Your input was goofy! Try again!");
    }
}
 
if (tryAgain) {
    request.getRequestDispatcher("/inputform.jsp").forward(request,response);
}
 
in your "inputform.jsp":
 
<%= request.getAttribute("myinputfield") %>
<% String s = "<input type=\"text\", name=\"myinputfield\",value=\"" + 
    (String) request.getParameter("myinputfield") + "\">";
    out.println(s);
%>
 

-----Original Message-----
From: Kevin Goethe [mailto:[email protected]]
Sent: Thursday, January 30, 2003 3:33 PM
To: [email protected]
Subject: 


Is there another way without diving into struts!   It sounds like I need to spend time in the future to learn about struts, but for now...  I need another solution.

At 02:50 PM 1/30/2003 -0500, you wrote:


Kevin: 

Have you considered using Struts?  It neatly solves this as well as many other problems. (plus is pure pleasure to work with!! :) 

Regards, 
Geeta 

Kevin Goethe wrote: 


 Use pure server-side (javascript not an option) 

Question: 
I need a way to preserve the input fields entered on a form after field validation occurs in the servlet.   If input error is detected during servlet validaton, how can I redisplay input form with values the user entered? 

I am using a servlets not jsp. 

Kevin Goethe 
Senior Analyst 
Northern Michigan University 
1401 Presque Isle 
501 Cohodas Building 
Marquette, MI  49855 

email:  [email protected] 
phone: 906-227-1253 
fax:      906-227-1890

Kevin Goethe
Senior Analyst
Northern Michigan University
1401 Presque Isle
501 Cohodas Building
Marquette, MI  49855

email:  [email protected]
phone: 906-227-1253
fax:      906-227-1890 



DISCLAIMER:
The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.