Phil Hedley wrote:
> Can someone give me a simple example of a servlet controller as stated in the
> MVC model.
> I've had a (very quick) look at the pet store example in the J2ee javasoft
> blueprints which seems to be very complicated for what it is doing.
>
The Struts project <http://jakarta.apache.org/struts> is an implementation of this
framework, with the addition of a nice custom tag library for creating interactive
forms.
>
> In my mind a controller is something that understands what should come next.
> In the examples I have seen so far, the controller is given the name of the next
> page it should forward the request to. It is the beans (business logic) that
> determine what comes next. The controller servlet seems to be used as a gateway
> to the jsp pages - is this for security ?
>
Controllers can certainly be used for security. An additional role they can play is
to assist you in separating presentation logic from business logic (so that you can
modify one without modifying the other).
For example, in Struts your forms submit themselves to a logical "action" name like
"/saveCustomer.do". There is a mapping table in the configuration parameters of the
controller servlet that chooses what Java class actually implements this action.
Therefore, you can change implementation classes by updating one configuration line
-- without having to update every form that submits to that action.
Likewise, as you point out, the business logic normally determines the next step in
the control flow. Usually, this is done by calling RequestDispatcher.forward() to
forward control to the particular JSP page that does the next part of the
presentation -- but this means your business logic has to know the actual URI of the
appropriate page, and you would have to modify business logic if you remodel the UI.
In Struts, there is a logical mapping for presentation components as well. So, your
business logic can say "forward control to the 'Main Menu' page", without knowing
what the name of that page is. Everything is managed in the configuration
parameters of the controller servlet.
>
> Would a web-application with hundreds of jsp pages have a sinlge servlet
> controller ? or would there be a single servlet controller handling the pages
> for each function of the web-application ?
>
With a properly designed framework, there is no inherent scalability problem in
having a single servlet controller. For example, using Struts, the actual business
logic that is executed is separated into individual Action classes, so adding new
business logic units (or modifying existing ones) means you only need to update a
configuration file, not modify the controller servlet itself.
>
> Thanks,
> Phil Hedley
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets