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