Title may sound a little vague but I'll give it a go. I have 2 servlets:
Action class
forwards the page to success or failure based on the inputs at index.jsp
ActionForm class
, Has getters and setters methodI have 3 jsp files:
I have 2 xml files:
I understand how web.xml works. My only doubt is, which one of the, one.java /two.java is called first from the struts.xml?
I tried to debug and found out that the ActionForm
class i.e two.java
is called first, then it returns the value to the Action
i.e one.java
.
But isn't Action class is supposed to execute first,and then the action form ? I mean This is what MVC architecture follows.
Please explain. Links to a very highly detailed workflow would be really helpful.
Struts 2 standard flow (Struts 2 architecture)Container maps the request in the web. xml file and gets the class name of controller. Container invokes the controller (StrutsPrepareAndExecuteFilter or FilterDispatcher). Since struts2.
The different actions that is performed and the struts flow in the struts life cycle are depicted below. 1) In first step user sends a request to the server for some resource. 2) The filterDispatcher accept the request and then it determines the appropriate action.
Struts Applications utilize the MVC designs, and the flow of demand occurs in a prescribed way: The user associated with the view after clicking on a connection or after that they submit present a form. After the interaction happens, the demand is sent to the controller.
The controller is responsible for intercepting and translating user input into actions to be performed by the model. The controller is responsible for selecting the next view based on user input and the outcome of model operations.
It is not surprising that ActionForm
class is called before Action
- Struts form should be filled with user's data before calling of Struts action method, any of which has 4 parameters:
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response
Second one - ActionForm
- should be ready to allow furthest data processing. I've just found great sequence diagram to illustrate all Struts lifecycle stages:
In short:
RequestProcessor
to find out appropriate action and form using struts-config.xml
RequestProcessor
gets Struts form object (or creates it if it doesn't exist), populates with data from request, initiates validation (if exists) and calls appropriate Struts action.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With