29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12.1.2 Struts framework<br />

True to the MVC design pattern, Struts applications have three major<br />

components: a servlet (the controller), JSPs (the view), and the application's<br />

business logic (the model).<br />

Struts model component<br />

Struts does not define its own model component. In a Web application (and a<br />

Struts application), most of the model (the business logic) can be represented<br />

using Java beans or EJBs. Access to the business logic is through Struts action<br />

objects (classes that subclass org.apache.struts.action.Action).<br />

The action object can handle the request and respond to the client (usually a<br />

Web browser), or indicate that control should be forwarded to another action. For<br />

example, if a login succeeds, a loginAction object may want to forward control to<br />

a mainMenu action.<br />

Action objects are linked to the application controller, and so have access to the<br />

methods of the servlet. When forwarding control, an object can indirectly forward<br />

one or more shared objects, including Java beans, by placing them in one of the<br />

standard collections shared by servlets.<br />

An action object can, for instance, create a shopping cart bean, add an item to<br />

the cart, place the bean in the session collection, and then forward control to<br />

another action, which may use a JSP to display the contents of the user's cart.<br />

Because each client has its own session, each also has its own shopping cart.<br />

Struts view component<br />

In general, a view represents a display of the domain model in a user interface.<br />

The view in a Struts application is made up of various components. JSPs are the<br />

main component. JSPs, of course, are not Struts components. However, Struts<br />

provides additional components that can be used by or with JSPs:<br />

► Form beans<br />

► Custom tags<br />

► HTML documents<br />

Form beans<br />

A form bean is an instance of the org.apache.struts.action.ActionForm class<br />

subclass that stores HTML or JSP form data from a submitted client request or<br />

input data from a link that a user has clicked. A form bean is a type of Java bean.<br />

An HTML or JSP form comprises fields in which the user can enter information.<br />

Chapter 12. Using Struts 385

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!