["Shah, Suneet" wrote:]
> I in a typical form processing situation, it is quite common to post the
> form to a servlet, which inturn would do some processing in the doGet/doPost
> methods and the possible redirect to another page. What is the recommended
> manner in achieving that in jsp,
[And, Craig McClanahan <[EMAIL PROTECTED]> said:]
> There is a very natural mechanism to enable this, called request
forwarding. I
> design my web applications using exactly the approach you describe:
I'd like to share a slightly different approach:
. Form calls a .jsp (which is a servlet of course)
. The jsp establishes a "bean" and has an opportunity to set some context
for the bean (the bean may serve several related jsp's). Almost all Java
code is in the bean.
. The jsp calls bean.service(request). As Craig has described, this bean
looks like and smells like a servlet. But the results are stored in one or
more objects and accessors are provided. An error message may be set.
. The jsp checks for an error. The jsp determines what error action to
take; not the "servlet bean." Typically, an error page is specified in the
jsp page, the error message is stashed in the exception and the exception
is fired.
. Otherwise, the jsp does her thing using the bean's accessors for dynamic
content
The difference between what Craig and I have said is that the jsp is more
involved in the context of the request and the response. Where are we in
the sequence of pages? What is the next page if this query can be
skipped? What do we do if there is an error? If there is only one row in
the "resultset"? If are no rows in the "resultset"? It seems cleaner to
me if the jsp handles "page flow logic," not the "servlet bean".
I've been worried that if I'm not doing as Craig suggests, I must be doing
something inelegant. I don't know -- but I like it.
Rick
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html