Thanks for the information.  Since there doesn't seem to be a method in the
servlet API to do this, I've come up with a solution:  Instead of submitting
the data directly to the servlet, the submit button sends the page to a jsp
which does nothing but populate the bean with the data from the form.  The
jsp then forwards to the servlet.  Something like:

<jsp:useBean id="abean" scope="session" class="APackage.ABean" />
<jsp:setProperty name="abean" property="*" />
<jsp:forward page="/servlet/APackage.ATest" />

This approach requires one additional .jsp per form/bean pair.  A more
clever jsp can probably be written which will work for all pages -- probably
by passing the bean name, class name and the name of the servlet that the
page will be forwarded to...

Yet another, probably better, way would be to just encapsulate the logic
from Tomcat in a helper class that will be used by the servelt to initialize
the bean.



>From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
>Reply-To: "Craig R. McClanahan" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: Something like jsp:setProperty in servlets?
>Date: Mon, 27 Dec 1999 17:23:17 -0800
>
>Java Guy wrote:
>
> > Is there something similar to jsp:setProperty is the servlet API?  I'm
> > trying to implement a "Model 2" application.  The "Submit" button on a
>(jsp
> > generated) HTML page sends the contents of the form to a servlet, which,
> > after processing the contents, forwards the request to a JSP page which
> > displays the results.)  In order to facilitate the processing of the
>data by
> > the servlet, I'd like a way to automatically get all the data that was
> > submitted by the form to be available in a bean, instead of getting each
> > attribute seperately in the servlet.
> >
> > If it were a jsp only solution,
> > <jsp:setProperty name="mybean" property="*" />
> >
> > at the top of the .jsp would do the trick.
> >
>
>There is nothing like this in the standard servlet API.  However, you could
>build a
>utility method that did this for you.  It could accept a JavaBean instance
>and your
>current HttpServletRequest as arguments, use the Java Reflection API to
>introspect
>the property names supported by that bean, and do the appropriate
>assignments based
>on the parameters included in the request.
>
>Because this process is so similar to what a JSP engine does for the
>servlet
>generated by your JSP pages, it might be possible to look at the source
>code for an
>existing JSP engine implementation (such as Jakarta's Tomcat at
><http://jakarta.apache.org>), extract the code that does this for that
>implementation, and use it as a starting point for your utility class.
>
>Craig McClanahan

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

===========================================================================
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

Reply via email to