D J wrote:

> I have a small servlet-base application that searches a back-end
> database.  I want to port this application from a monolithic servlet
> (with embedded HTML) into the "Model 2" approach described in the JSP
> spec (using JSDK2.1 and JSP.92).  Being very new to JSP, I have some
> questions.
>

Good choice ... unmixing the presentation and the processing is a better idea
IMHO.

>
> Imagine this user error situation.  The user is presented with a HTML
> form that allows them to enter a name to search for.  Currently in my
> servlet app, once the form is submitted, the servlet checks for
> invalid input.  If the input is invalid (ie. the search for field is
> blank), I return the original search form with a descriptive error
> message.  This way, I don't want waste the user's time redirecting
> their browser to another error page (and thus force them to click
> return to the search form).
>
> How can such an user interface be implemented in the Model 2 approach?
>
> Could this work?
> Make the original search form a JSP file that submits the form to a
> search servlet.  Upon discovering invalid input, the servlet would
> create a "UserError" bean, set the "message" property and then send
> it back to the search JSP.  The JSP would contain some Java scripting
> to detect the UserError bean and display the error.
>
> DJ
>

I deal with this kind of thing in a very similar manner, using the following
approach:

* Define a bean whose properties are all of the entry fields on a form.
* In a servlet, create this bean with default values and stuff it in the
session
* Forward control to the JSP page, which is programmed to use the current
  values in the bean as the data in the input fields (using the <DISPLAY> tag
  to grab them).
* User fills out the form and submits to a servlet, which does the validation.
* In addition to validation, the servlet updates the bean properties to reflect

  the last values entered by the user.
* If the servlet discovers a problem, create an error message bean with some
  sort of message describing the problem, and stash it in the request (so you
  don't have to worry about cleaning it up later).
* Then, forward control back to the JSP page with the original input form.
* Include some conditional logic (in my case it's at the top of the page) to
  extract and display the error text.  Something like:
    <excludeif property="errorbean:message" match="null">
    <display property="errorbean:message">
    </excludeif>
* When the JSP page displays the form again, it will grab the original bean's
  values, which now contain whatever he/she entered last time.

Craig McClanahan

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to