First, Struts 2.x overview
Do not inherit action from any class
Struts 2 's action does not necessarily implement the action interface or inherit Actionsupport, and any pojo can do the action, as long as the action has the public String execute () method.
Executable method of Action
Execute () is the default method for action. Struts 2 can also perform other methods of action, as long as these methods have no parameters and return a string type. These methods can also have throws declarations, or not. Struts 2 determines, at run time, whether an executable method (parameter, return value) is performed based on the characteristics of the method and is executed through reflection.
Method of executing action via URL
Http://localhost:8080/struts2/loginPerson!logout.action will execute the Loginperson logout () method.
Configure the execution method to action
Struts.xml
<action name< Span style= "color: #0000ff;" >= "*person" Class= " Com.helloweenvsfei.struts2.action.LoginAction " method = "{1}" > <result name= "Success" >/welcome.jsp</ result></action>
Specify the action directory in Web. xml
0 Configuration is the location of the action package that must be specified in the filter for Web. XML, otherwise the action configuration is loaded by default to Struts.xml.
<Filter> <Filter-name>Struts</Filter-name> <Filter-class>Org.apache.struts2.dispatcher.FilterDispatcher</Filter-class> <Init-param> <Param-name>Actionpackages</Param-name> <Param-value>Com.helloweenvsfei.struts2.action</Param-value> </Init-param> <!--
<init-param> <param-name>struts.action.extension</param-name> <param-value& Gt;helloween</param-value> </init-param> - </Filter>
Summarize:
The Java Web uses threads to process a user's request, and one request corresponds to a processing thread. Struts 2 assigns an action object to each processing thread, injects the submitted parameters into the Action property, and invokes the action's related methods such as execute () to complete the business logic. Therefore, the action of Struts 2 will have multiple objects. After processing, the thread runs and the action is discarded. The action of Struts 2 is thread-safe.
Struts 2 automatically completes the work of taking parameters such as HttpServletRequest, discarding httpservletreques, HttpServletResponse and other servlet APIs, making development and testing easier.
Java Web Integration Development (2)--Struts