Hi! Ted,

I am new to Struts framework and is still in the process of understanding
the design and the architecture. I have the following comments on your
overview. I might not be totally correct and would appreciate if you or
others can find anything wrong with my understanding based on my comments.

----------------------------------------------------------------------------
------------------------------------------
When initialized, the controller parses a configuration resource file. The
configuration resource defines (among other things) the servlet mappings for
the application. The controller uses these mappings to determine how to
route the requests it receives.

At a minimum, a mapping must include (1) the request this mapping handles
and (2) the servlet that handles it.

---<COMMENT>
It's not clear what you mean by (2) the servlet that handles it. In struts
framework there is only one servlet that handles all the web requests which
is ActionServlet configured by web.xml to handle all URL pattern of *.do.

Every action mapping in struts-config.xml should have at least these 2
required attributes
1.      path which is the path info portion of the http request
2.      type which is the Action's java class name that should implement Action
interface and have the business logic in        its perform method.
---</COMMENT>

The action's servlet can then handle the request, and return a HTTP response
to the controller, which the controller can pass back to the client.

---<COMMENT>
I think you have a wrong understanding that action classes are servlets. No
they are regular java class that implements Action interface and provide
perform method definition that is the actions business logic.  Moreover
Action Classes never return response to the controller servlet i.e.
ActionServlet. They always return ActionForward, which might be null.

Action classes normally executes the business logic using the form bean data
passed in the perform method affecting the model state and can then decide
which forward page should it return to the ActionServlet to render the view.
Action classes can also generate response back to the client in which case
they wont return any view forward to the ActionServlet. If the returned
ActionForward is null ActionServlet assumes that Action class has written
the response back to the client.
---</COMMENT>

The action's servlet can also indicate if control should be forwarded to
another action. For example, if a login succeeded, the loginAction servlet
may wish to forward control to the mainMenu action.

---<COMMENT>
loginAction should be ur Action Class not a servlet and on success it should
return forward to "mainMenu.jsp" which is a
view component not action.

For login you should have a action mapping as follows
<action path="/loginUser
        name="loginBean"
        scope="request"
        type="com.acme.LoginAction >
        <forward name="success" path="/mainMenu.jsp" />
        <forward name="failure" path="/login.jsp" />
</action>
</COMMENT>

When forwarding control, a servlet can also include a shared object, or
JavaBean, by storing it within a collection that other servlets can access.
There are standard collections for a page, request, session, and application
that are shared by all servlets and JSPs in the same Web application.

---<COMMENT>
Action Classes executes the business logic using the form bean data and
affects the model state. It might create some bean as a content that it
would set as an attribute in the required scope i.e request, session or
servlet context for the view rendering JSP to use.

Page scope is only applicable for JSP's and is not shared by all JSP's. It
is only valid for the current request
processing JSP.
---</COMMENT>

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 store the data for a input form in a form
bean, which is automatically maintained through the user's Struts session.
---<COMMENT>
Not necessarily. FormBean would be maintained through user's session if the
formbean has a scope of session.
---</COMMENT>

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 display
any validation errors, along with the other data entered.
---<COMMENT>
Form beans are used basically to gather HTML form data upon which Action
class operates on. JSP does not use form bean to display validation errors.
It uses ActionErrors for it.
---</COMMENT>


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

Thanks,
Shiraz Zaidi

###

> -----Original Message-----
> From: Ted Husted [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 18, 2000 8:02 AM
> To: Struts List
> Subject: What's Struts ...
>
>
> Annexed is an overview of the Struts architecture that I put together
> for my spec. I'd be very interested in any comments or criticisms, or
> anything I've got totally wrong. Of course, if anyone wants to use any
> part of this for their own project, please do.
>
> I'm now dissecting the example application (15 Dec build) to add JDBC
> database support along with i18n switching (per Kapur and Geary).
>
> My own application is database-centric, and I want to be sure I
> understand the arcitecture right before starting my own code. If anyone
> else has done work along these lines, I'd be very interested in your
> comments or samples.
>
> -- Ted Husted.
>
>
>

Reply via email to