Spring集成Struts
时间:2006-12-31 来源:liulibo
1.Web.xml被装载,解析applicationContext.xml获取spring应用程序上下文(若有上下文装载器插件可不用监听)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.配置ActionServlet
<servlet>
<servlet-name>ActionServlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>ActionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
3.继承support(通过Spring应用程序上下文获取Biz对象)方法一:
1.在applicationContext.xml创建对象
<bean id="PersonBiz" class="biz.PersonBiz">
</bean>
2.ActionServlet继承ActionSupport通过Spring应用程序上下文获取对象
PersonBiz biz = (PersonBiz)getWebApplicationContext().getBean("PersonBiz");
3.委托Spring请求处理(通过注入Biz获取对象)方法二:
在struts-config.xml文件中声明委托Spring请求处理
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>
在struts-config.xml文件中声明使用上下文装载器插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/proxy.xml"/>
</plug-in>
在proxy.xml中指定请求及创建对应的Action
<bean name="/login" class="action.PersonAction">
<property name="biz">
<ref bean="PersonBiz"/>
</property>
</bean>
<bean id="PersonBiz" class="biz.PersonBiz">
</bean>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.配置ActionServlet
<servlet>
<servlet-name>ActionServlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>ActionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
3.继承support(通过Spring应用程序上下文获取Biz对象)方法一:
1.在applicationContext.xml创建对象
<bean id="PersonBiz" class="biz.PersonBiz">
</bean>
2.ActionServlet继承ActionSupport通过Spring应用程序上下文获取对象
PersonBiz biz = (PersonBiz)getWebApplicationContext().getBean("PersonBiz");
3.委托Spring请求处理(通过注入Biz获取对象)方法二:
在struts-config.xml文件中声明委托Spring请求处理
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>
在struts-config.xml文件中声明使用上下文装载器插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/proxy.xml"/>
</plug-in>
在proxy.xml中指定请求及创建对应的Action
<bean name="/login" class="action.PersonAction">
<property name="biz">
<ref bean="PersonBiz"/>
</property>
</bean>
<bean id="PersonBiz" class="biz.PersonBiz">
</bean>
相关阅读 更多 +