Control Flow in Struts 1.2 (Life Cycle)

The name may seem a little vague, but I'll give it away. I have 2 servlets:

  • one.java: Extends the Action class redirects the page to success or failure based on index.jsp inputs
  • two.java: Extends the ActionForm class method, Has getters and seters

I have 3 jsp files:

  • index.jsp: Welcome pages and request a username combination
  • success.jsp: Called if the combination is correct.
  • failure.jsp: Called if the combination is false

I have 2 xml files:

  • web.xml: DD
  • struts-config.xml: Struts configuration file

I understand how web.xml works. My only doubt is that one of <, b> one.java/two.java is called first from struts.xml?

I tried to debug and found out that the ActionForm ie two.java class is ActionForm two.java , then it returns the value in Action ie one.java .

But shouldn't the Action class be executed first, and then the action form? I mean, this is what follows the MVC architecture.

Please explain. Links to a very detailed workflow will be really helpful.

+7
java struts-1 struts struts-config
source share
1 answer

It is not surprising that the ActionForm class ActionForm called before the Action - the Struts form must be populated with user data before calling the Struts action method, any of which has 4 parameters:

 ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response 

The second - ActionForm - should be ready for further data processing. I just found a great sequence diagram to illustrate all the steps in the Struts life cycle:

enter image description here

In short:

  • After receiving a client request, calls the Struts RequestProcessor Frontts controller to find the appropriate actions and form using struts-config.xml
  • RequestProcessor receives a Struts form object (or creates it if it does not exist), is populated with data from the request, initiates a check (if exists), and calls the corresponding Struts action.
  • The Struts action performs all necessary operations.
+12
source share

All Articles