On 6/19/2000 at 12:25 AM Shiraz Wasim Zaidi wrote:
> I have the following comments on your overview. 

Thank you! Does this sound better? 

--

At a minimum, a mapping must specify (1) a request path and (2) the
object type to act upon the request. The action object can handle the
request and respond to the client, or indicate that control should be
forwarded to another action. For example, if a login succeeds, the
loginAction object may wish to forward control to the mainMenu action. 

Action objects are linked to the application's controller, and have
access to that servlet's methods. When forwarding control, an object
can also indirectly forward one or more objects, including JavaBeans,
by placing them in one of the standard collections shared by Java
servlets. 

The action object can handle the request and respond to the client, or
indicate that control should be forwarded to another action. For
example, if a login succeeds, the loginAction object may wish to
forward control to the mainMenu action. 

Action objects are linked to the application's controller, and so have
access to that servlet's methods. So when forwarding control, an object
can indirectly forward one or more shared objects, including JavaBeans,
by placing them in one of the standard collections shared by Java
servlets. 

<snip/>

The form bean can be used by a JSP to collect data ... by an action
servlet to validate what the user enters ... and then by the JSP again
to re-populate the form fields. In the case of validation errors,
Struts has a shared mechanism for raising and displaying error
messages. 

---

(Complete update annexed.)



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/

What's Struts?

Struts uses a switchboard, or controller, servlet to route requests to other Struts 
objects. When initialized, the controller parses a configuration resource file. The 
configuration resource defines (among other things) the action mappings for the 
application. The controller uses these mappings to turn HTTP requests into application 
actions. 

At a minimum, a mapping must specify (1) a request path and (2) the object type to act 
upon the request. The action object can handle the request and respond to the client, 
or indicate that control should be forwarded ot another action. For example, if a 
login succeeds, the loginAction object may wish to forward control to the mainMenu 
action. 

Action objects are linked to the application's controller, and have access to that 
servlet's methods. When forwarding control, an object can also indirectly forward one 
or more objects, including JavaBeans, by placing them in one of the standard 
collections shared by Java servlets. 

The action object can handle the request and respond to the client, or indicate that 
control should be forwarded ot another action. For example, if a login succeeds, the 
loginAction object may wish to forward control to the mainMenu action. 

Action objects are linked to the application's controller, and so have access to that 
servlet's methods. So when forwarding control, an object can indirectly forward one or 
more shared objects, including JavaBeans, by placing them in one of the standard 
collections shared by Java servlets. 

So, one action object can create a shopping cart bean, add an item to the cart, place 
the bean in the session collection, and then forward control to another action that 
may use a JSP to display the contents of the user's cart. Since each client has their 
own session, they will each also have their own shopping cart. In a Struts 
application, most of the business logic is represented using JavaBeans.

JavaBeans can also be used to manage input forms. A key problem in designing Web 
applications is retaining and validating what a user has entered between requests. 
With Struts, you can easily store the data for a input form in a form bean. The bean 
is saved in one of the standard, shared contexts, so that it can be used by other 
objects.

The form bean can be used by a JSP to collect data from the user ... by an action 
object to validate the user entered ... and then by the JSP again to re-populate the 
form fields. In the case of validation errors, Struts has a shared mechanism for 
raising and displaying error messages. 

Form beans are defined in the configuration resource and linked to an action mapping 
using a common name. When a request calls for an action that uses a form bean, the 
controller servlet either retrieves or creates the form bean, and passes it to the 
action object. The action object can then check the contents of the form bean before 
its input form is displayed, and also queue messages to be handled by the form. When 
ready, the action object can return control with a forwarding to its input form, 
usually a JSP. The controller can then respond to the HTTP request and direct the 
client to the Java Server Page.

The Struts framework includes custom tags that can automatically populate fields from 
a form bean. The only thing most Java Server Pages need to know about the rest of the 
framework is the proper field names and where to submit the form. Components like the 
messages set by the action object can be output using a single custom tag. Other 
application-specific tags can also be defined to hide implementation details from the 
JSPs.

The custom tags in the Struts framework are designed to use the internationalization 
features built into the Java platform. All the field labels and messages can be 
retrieved from a message resource, and Java can automatically provide the correct 
resource for a client's country and language. To provide messages for another 
language, simply add another resource file.

Other benefits to this approach are consistent labeling between forms, and the ability 
to review all labels and messages from a central location. 

For the simplest applications, an action object can handle the business logic 
associated with a request. However, in most cases, an action object should pass the 
request to another object, usually a JavaBean. To allow resuse on other platforms, 
business-logic JavaBeans should not refer to any Web application objects. The action 
object should translate needed details from the HTTP request and pass those along to 
the business-logic beans as standard Java variables. 

In a database application, the business-logic beans might connect to and query the 
database and return the result set back to the action's servlet ... to be stored in a 
form bean, and then displayed by the JSP. Neither the action's servlet nor the JSP 
need to know (or care) where the result set comes from. 

The Struts framework is compliant with the classic Model-View-Controller paradigm, 
which is the architecture recommended by Sun and most other vendors. 

In Struts, the ActionServlet object (described above) is the MVC controller, the view 
is handled by JSP or directly by an Action object, and the model is handled with 
business-logic beans, or directly by an Action object. 

-- Ted Husted, 19 Dec 2000 <[EMAIL PROTECTED]>.

###

Reply via email to