1. Add the struts2 package
2. Configure the struts2 filter in web. xml
[Java]
<Filter>
<Filter-name> struts2 </filter-name>
<Filter-class> org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-name> struts2 </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>
3. Write struts. xml and test the application to verify that the struts configuration is correct.
[Java]
<Package name = "h" extends = "struts-default">
<Action name = "login" class = "org. ymm. actions. LoginAction" method = "mlogin">
<Result name = "success" type = "redirect"> login. jsp </result>
<Result name = "fail"> fail. jsp </result>
</Action>
</Package>
4. If struts is OK, add the spring support package and configure the listener ContextLoaderListener (let spring be loaded prior to struts, and manage struts actions later by spring)
Note: struts2-spring-plugin-2.3.3.jar must be added to this pack
[Java]
<Context-param>
<Param-name> contextConfigLocation </param-name>
<Param-value> classpath: beans. xml </param-value>
</Context-param>
<Listener>
<Listener-class> org. springframework. web. context. ContextLoaderListener </listener-class>
</Listener>
The loading sequence of web. xml is context-param-> listener-> filter-> servlet (because listener is prior to filter, start spring with listener)
See: http://blog.csdn.net/without0815/article/details/7689661
In the struts2 configuration file, add the <constant name = "struts. objectFactory" value = "spring"> </constant> attribute
5. Compile beans. xml beans, such as beans that manage actions in sturts:
[Java]
<Bean id = "spring" class = "org. ymm. actions. LoginAction">
.......
</Bean>
Author: without0815