集成Structs1.x

一. structs1.x插件集成
contextClass:可选,用于指定WebApplicationContext实现类,默认是XmlWebApplicationContext;

contextConfigLocation:指定Spring配置文件位置,如果我们的ActionServlet 在 web.xml 里面通过 hello指定名字为“hello”,且没有指定contextConfigLocation,则默认Spring配置文件是/WEB-INF/hello-servlet.xml;

namespace:因为默认使用ActionServlet在web.xml定义中的Servlet的名字,因此如果想要使用其他名字可以使用该变量指定,如指定“hello”,将加载的Spring配置文件为/WEB-INF/hello-servlet.xml;

//structs-config.xml
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">  
    <set-property property="contextClass" value="org.springframework.web.context.support.XmlWebApplicationContext"/>  
    <set-property property="contextConfigLocation" value="/WEB-INF/hello-servlet.xml"/>  
    <set-property property="namespace" value="hello"/>  
</plug-in>  
(注:通用配置的Spring Web容器将作为ContextLoaderPlugin中创建的Spring Web容器的父容器存在,然而可以省略通用配置而直接在struts配置文件中通过ContextLoaderPlugin插件指定所有配置文件。)

二.集成Spring+Structs1.x

    (注:使用插件方式时Action将在Spring中配置而不是在Struts中配置了)

Spring提供两种方式:
1.将Struts配置文件中的的type属性指定为DelegatingActionProxy,然后在Spring中配置同名的Spring管理的Action Bean;

//先在Structs的配置文件structs-config.xml中定义action
<action path="/hello3" type="org.springframework.web.struts.DelegatingActionProxy">  
    <forward name="hello" path="/WEB-INF/jsp/hello.jsp"/>  
</action>  
//在Spring配置文件中servlet-config.xml中定义对应Action的bean(即 bean的name与action的path要一致)
<bean name="/hello3" class="cn.javass.spring.chapter10.struts1x.action.HelloWorldAction3">  
    <property name="message" ref="message"/>  
</bean>  

2.DelegatingRequestProcessor方式与Spring集成:

//structs-config.xml
//1.换掉Struts默认的RequestProcessor,
<controller>  
    <set-property property="processorClass"  
         value="org.springframework.web.struts.DelegatingRequestProcessor"/>  
</controller> 

//2.进行Action定义
<action path="/hello4" type=" cn.javass.spring.chapter10.struts1x.action.HelloWorldAction3">  
    <forward name="hello" path="/WEB-INF/jsp/hello.jsp"/>  
</action>  
//在spring-config.xml定义action对应的bean(即 bean的name与action的path要一致)
<bean name="/hello4" class="cn.javass.spring.chapter10.struts1x.action.HelloWorldAction3">  
    <property name="message" ref="message"/>  
</bean>  
    (注:Struts通过DelegatingRequestProcessor去到Spring Web容器中查找同名的Action Bean,没有代理Action,推荐使用该方式)

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值