Spring and struts Integration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.