Working of Struts 2
Struts2 has a filter dispatcher whose fully qualified name is org.apache.struts2.dispatcher.FilterDispatcher. To use this Dispatcher it has to be registered in the deployment descriptor as below.
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
<filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-patter>
</filter-mapping>
Struts splits the task processing in its filter dispatcher into subcomponents called interceptors. Eg the work of the first interceptor is to populate the action object with the request parameters.
In Struts action method is executed after the the action’s properties are populated.
The method in the action returns a String. Eg if it returns a “Success” , or “failure”, depending upon the return value it can be forwarded to the result page. The forwarded result may not always be a jsp, it can even be a file to be downloaded.
Working of the Filter Dispatcher
The work of the Filter Dispatcher is to first verify the request URI and determine which action to invoke. The Filter Dispatcher may do this using string manipulation method. But this is not a good method because if the URI changes during development the Filter has to be recompiled when ever it changes
So struts uses the configration file struts.xml which matches URIs with action classes. One has to create a struts.xml and put it in the WEB-INF/classes folder. In this xml file the action definitions,concrete action class name, URI to invoke the action should be placed. If the name of the method in the action is other then execute then it should be also mentioned in the web.xml.
The action class should have at least one result to tell what to do after the action method is executed. It can have multiple results if the action method returns different results depending upon the user input.
When struts starts it reads the struts.xml. When ever struts gets a request it checks the timestamp of the struts.xm. Itf it is recent then when it was last time loaded then it is reloaded, thereby if one makes changes to the struts.xml, restarting the server is not required.
During each action invocation the filter dispatcher does the following steps.
1) It consults the Configuration Manager to find out which action to depending on the request URI.
2) Uns the interceptors registered with this action. First interceptor will populate the properties of the action.
3) Executes the action method.
4) Executes the result.
Services: - Working of Struts 2 Homework | Working of Struts 2 Homework Help | Working of Struts 2 Homework Help Services | Live Working of Struts 2 Homework Help | Working of Struts 2 Homework Tutors | Online Working of Struts 2 Homework Help | Working of Struts 2 Tutors | Online Working of Struts 2 Tutors | Working of Struts 2 Homework Services | Working of Struts 2