A First Look at Struts

I l @ ve RuBoard

It's very easy to provide a complicated description of how MVC works. I'm going to try to provide a simple, if slightly incomplete version, using Struts as an example.

Struts is an Apache model 2 implementation. Describing Struts is a bit of a chicken-and-egg problem because you're really developing three pieces of the application at once. But it might be easier to understand by looking at it first from the perspective of a finished site.

NOTE

Struts was written by Craig McClanahan of Sun Microsystems. I'm grateful to Craig for suggestions that he made regarding this chapter. Assume that all mistakes are mine and that all golden nuggets are his.


A user loads myAccount.jsp, a normal JSP with some custom tag libraries loaded to support Struts. When the user clicks on a link or submits a form, instead of being sent directly going to another JSP, the data is copied from the request into an ActionForm object with properties that mirror the data that is being sent from the page ”this is the "model" part of MVC.

WHAT ARE TAGLIBS ?

A taglib allows a developer to embed functionality into a JSP document using a format that looks more like HTML. You've already seen taglibs in use, in the form of the <jsp:useBean> tag.

Tomcat allows developers to write their own taglibs, and the Struts developers have taken advantage of this fact to extend JSP to handle specific functionality that Struts wants to provide to JSP pages.

Next , control is passed to an Action object, which runs any business logic needed to complete the user's request and determines what page the user needs to go to next. Action returns an object to the Controller (Struts), which uses an XML file to determine what JSP to dispatch to based on the status returned from Action .

Finally, the new JSP displays any results (the "view"), and sets up for the next user request.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net