Struts hibernate Spring 整合

一、Struts 和 Spring 整合

第1步:将spring做为插件加到struts_config.xml中:

<struts-config>

  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">

   <set-property property="contextConfigLocation"

     value="/WEB-INF/applicationContext.xml" />

  </plug-in>

</struts-config>

这是加载spring的context

第2步:将控制权交给Spring定制的Action处理,在 struts_config.xml的配置action的type:

<action-mappings>

   <action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"

     name="loginForm">

     <forward name="success" path="/main.jsp" />

     <forward name="failure" path="/login.jsp" />

   </action>

</action-mappings>

DelegatingActionProxy同样是 org.apache.struts.action.Action的一个子类,它将把调用请求转交给真正的Action实现。

第3步:在spring的配置文件applicationContext.xml中配置Action的bean

<bean name="/login" class="cn.uolee.wap.LoginAction" singleton="false">

   <property name="userDAO">

     <ref bean="userDAOProxy" />

   </property>

</bean>

这样当用户请求login.do页面的时候, DelegatingActionProxy将在 applicationContext.xml中获取真正的Action实例,并且调用Action的execute()方法。

下面是 DelegatingActionProxy的 execute方法代码:

public ActionForward execute(

  ActionMapping mapping,

  ActionForm form,

  HttpServletRequest request,

  HttpServletResponse response)

  throws Exception {

  //获得实际的Action实例,并将请求转交

  Action delegateAction = getDelegateAction(mapping);

  return delegateAction.execute(mapping, form, request, response);

  }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值