spring和struts整合

1.添加struts2包

2.在web.xml配置struts2过滤器

<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.编写struts.xml,写测试应用程序确保验证struts配置正确

<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.如果struts已经ok,添加spring支持包,配置监听器ContextLoaderListener (让spring先于struts被加载,为后来struts的action被spring管理)

注:必须要加struts2-spring-plugin-2.3.3.jar此包

<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>
web.xml 的加载顺序是: context-param -> listener -> filter -> servlet  (由于listener先于filter,所以用listener启动spring)

详细看:http://blog.csdn.net/without0815/article/details/7689661

在struts2配置文件,加入 <constant name="struts.objectFactory" value="spring"></constant> 属性


5.编写beans.xml的bean,例如管理sturts中action的bean:

<bean id="spring" class="org.ymm.actions.LoginAction">
	.......
</bean>



你可能感兴趣的:(spring,bean,struts,servlet,filter,action)