If the JSP page has input fields possible reasons to use the bean include
the following:

1) The jsp:setProperty name="fooBean" property="*"   will "iterate over the
current ServletRequest parameters, matching parameter names and value
type(s) to property names and setter method type(s), setting each matched
property to the value of the matching parameter." Java Server Pages 1.1
Specification - Public Release 2, p. 67.

2) If you decide to use the Servlet as the View Controller and relegate the
JSP to formatting and display, you would not invoke the JSP page until the
unit of work the Servlet was processing was complete. But a bean would still
have benefit as you could write a simple method that  used reflection and
the bean interface to map the Servlet request parameters to the bean. This
mapping assumes that the ServletRequest  parameter names match the
associated bean property names. In this vein you might have one Bean per JSP
page.

Beans used in this way encapsulate the data of the ServletRequest object.

regards,
Bill Bomberry

> -----Original Message-----
> From: Patrick Regan [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, January 04, 2000 1:09 PM
> To:   [EMAIL PROTECTED]
> Subject:      Beans vs. Classes
>
> I am trying to determine what the benefits are to using beans over just
> an ordinary class.  From the little that I know, I don't see the
> benefit.
>
> Take the calendar example for a bean (here is the JSP code) :
>
> <html>
> <jsp:useBean id="clock" class="calendar.jspCalendar"/>
> <ul>
> <li>Day:<%= clock.getDayOfMonth() %>
> <li>Year:<%= clock.getYear() %>
> </ul>
> </html>
>
> Versus just an ordinary server-side java class (here is the JSP code):
>
> <html>
> <% JspCalendar clock = new JspCalendar() %>
> <ul>
> <li>Day:<%= clock.getDayOfMonth() %>
> <li>Year:<%= clock.getYear() %>
> </ul>
> </html>
>
> Can someone give me an idea of why I should use beans over a regular
> server-side class?
>
> Thanks,
> Patrick Regan
>
> ==========================================================================
> =
> 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

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