下面是记录struts和spring的整合第二种方式,以防止忘记。
action交给spring管理,首先需要在struts配置文件中配置一个spring插件,
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/ctxconf/spring/applicationContext.xml/>
</plug-in>
并且所有的action中的type都需要配置为:
<action input="/index.jsp"
name="LoginForm"
parameter="method"
scope="request"
path="/login"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="success1" path="/jsp/interface/demo.jsp" />
<forward name="success" path="/jsp/interface/main.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
并且所有的action都需要在spring中注册
<bean name="/login" class="com.snt.web.actions.LoginAction">
<property name="loginDAO">
<ref bean="loginDAO" />
</property>
</bean>
此时在web.xml中也不需要在配置上下文监听的信息了
其中注意的地方有spring中注册action的name与struts配置文件中path的值一样,必须一样。