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.

Reply via email to