• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Doubts ...understanding the struts architecture :(

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey i am new to struts and following is my understanding.. Please correct me whereever possible

In a simple struts application , when the controller gets a request it creates a request object (containing the HTTP method, HTTP protocol and URI) and a response object.

It then checks the mapping files and decides which action class to instantiate..(Its Just one instance of every action irrespective of the number of requests coming in ?? right? ).

The mapping file is then again checked for the corresponding form-bean element.....what does it do then ..?? I get confused with the part...does it invoke a different form instance for each request or uses the same form instance..... Please can someone clarify the processing.


for an existing code ...in the execute declaration i have

---------------
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
-----------------

and in the body for execution i have
-----------------------
DBupdateForm form1 = (DBupdateForm)form;
-----------------------

Please can someone explain this processing step by step.

Thanks in advance...
Gaurav
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gaurav,

Struts is a framework where many things are taken care by the "controllers" and the developers can focus on the business logic.

For a request, the Form Class (extends ActionForm/ ValidatorForm) is set with the values and then the form is passed to the controller Action Class (which extends Action). (ofcourse you have to cast the form and use it!!).

Now which JSP has which Form Class is "told" by the struts-config.xml. (in <form-beans> .
Then if any <form action> is called then again struts-config.xml is checked for the mapping and then the corresponding action class is called.

Utimately, when the request reaches the Action class, the form has already been populated with the values. We just have to type cast it and use it. Then based on the logic there are some forwards(mapping.findForward("some-name")) which are again checked for, in the struts-config.xml and the page it forwarded to that particular JSP.

Hope it helps to clear some of your doubts.

Regards,
Roshani
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Roshani,
Thanks for the prompt reply, that does help...

But i still have one question .....

Following are the points mentioned in Oreilly's Programming jakarta struts text....


The following steps illustrate how the framework processes ann ActionForm
for every request:
1. Check the mapping for the action and see if an ActionForm has been configured.
2. If an ActionForm is configured for the action, use the name attribute from the action element to look up the form bean configuration information.

3. Check to see if an instance of the ActionForm already has been created.

4. If an ActionForm instance is present in the appropriate scopee and it's the same type as needed for the new request, reuse it.
5. Otherwise, create a new instance of the required ActionForm & store it in the
appropriate scope (set by the scope attribute for the action element).
6. Call the reset( ) method on the ActionForm instance.


What does scope and type refer to in the 4th point?? There is just one instance for the Actionform for a particular url type. right??

I mean if i have a URL like http://localhost:8080/MYapp/doThis.do?a=10&b=20&c=30

There will be just one instance of the actionform for all URLs of this type right...
I mean if another request
http://localhost:8080/MYapp/doThis.do?a=40&b=50&c=60 comes in a new ActionForm instance will not be created? Instead the actionform object passed to the Action Class will have new values for a,b,c right??
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Scope" refers to one of the four scopes in J2EE Web Applications (page, request, session, and application). However, the only scopes that make any sense for an ActionForm are request and session.

If you specify "request" in your action mapping, Struts will create a new ActionForm for every request, since the one used by the previous request is out of scope.

If you specify "session" scope, Struts will look in the session first to see if it's already there. If it is there, Struts will use the existing object. If it isn't there Struts will instantiate a new one. The comment about "type" simply means that Struts will verify that the found object is of the type you specified in the action mapping in your struts-config.xml file. If you've coded your ActionForms and Action Mappings in struts-config.xml properly (without duplicate ActionForm names), it will be.
[ September 25, 2006: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also keep in mind that session scope is per user. If you have 1000 users hitting the same URL/Action each of those users will have their own session, thus there will be 1000 different instances of your form bean (and only 1 instance of your action).

- Brent
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot


Gaurav
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic