You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shiraz Wasim Zaidi <sw...@flash.net> on 2000/06/19 07:25:11 UTC

RE: What's Struts ...

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 <te...@husted.com>.

Thanks,
Shiraz Zaidi

###

> -----Original Message-----
> From: Ted Husted [mailto:news.ted@husted.com]
> 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.
>
>
>


RE: What's Struts ...

Posted by Ted Husted <ne...@husted.com>.
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/


Re: What's Struts ...

Posted by craig mcclanahan <Cr...@eng.sun.com>.
Steve A Drake wrote:
> 
> On Mon, 19 Jun 2000, Shiraz Wasim Zaidi wrote:
> 
> > 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.
> 
>  Just so we're all on the same page here, according to the
> (0.5) documentation, an Action class is not a servlet but it has a simliar
> lifecycle to a servlet in that only one Action object is instantiated. So,
> you must consider multi-threading issues when coding your Action class
> (like you would with a servlet). Someone please correct me if this is not
> the case.
> 

This is correct for all versions of Struts, although in Struts 1.0
Action is a base class that you extend, rather than an interface that
you implement.  In addition, the Action class now receives lifecycle
indications through the call to setServlet() -- a non-null argument
tells you that this Action is about to be invoked for the very first
time, and a null argument tells you that this instance has been taken
out of service (currently, this only happens when the web application is
shut down.)


> > 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>
> 
>  And, looking at the processActionForm() method in the ActionServlet
> class, session is the default scope for ActionForm beans.

Session is the default scope; request is the other option.  It makes for
more scalable applications if you can use it, but requires that all of
the properties of your ActionForm bean be included in the page.

Craig McClanahan

RE: What's Struts ...

Posted by Ted Husted <ne...@husted.com>.
Shiraz, 

I revised my What's Strut's and Walking Tour (part 1) article in
response to your comments and others I received privately. 

If you get a chance to look at it again <
http://husted.com/about/support/struts/ >, please let me know if you
see any other inaccurate statements. 


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



RE: What's Struts ...

Posted by Shiraz Wasim Zaidi <sw...@flash.net>.
>an Action class is not a servlet but it has a simliar lifecycle to a
servlet
>in that only one Action object is instantiated.
Not always true. If your servlet implements SingleThreadModel interface then
container creates a pool of servlet instances.

>  And, looking at the processActionForm() method in the ActionServlet
> class, session is the default scope for ActionForm beans.
Yeah you are correct.

-Shiraz Zaidi


RE: What's Struts ...

Posted by Steve A Drake <sa...@comet.ucar.edu>.
On Mon, 19 Jun 2000, Shiraz Wasim Zaidi wrote:

> 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.

 Just so we're all on the same page here, according to the 
(0.5) documentation, an Action class is not a servlet but it has a simliar
lifecycle to a servlet in that only one Action object is instantiated. So, 
you must consider multi-threading issues when coding your Action class
(like you would with a servlet). Someone please correct me if this is not
the case.


> 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>

 And, looking at the processActionForm() method in the ActionServlet
class, session is the default scope for ActionForm beans.