spring 2.0.3 整合 struts1.3.5

1.将相关jia包贴到lib下边

2.配置web.xml 如下

//struts的配置

 <servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>
   org.apache.struts.action.ActionServlet
  </servlet-class>
  <init-param>
   <param-name>config</param-name>
   <param-value>                                         \\加载多个struts配置文件用逗号隔开
    /WEB-INF/struts-config.xml,    
    /WEB-INF/struts-config-pay.xml
   </param-value>
  </init-param>
  <init-param>
   <param-name>debug</param-name>
   <param-value>3</param-value>
  </init-param>
  <init-param>
   <param-name>detail</param-name>
   <param-value>3</param-value>
  </init-param>
  <load-on-startup>0</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>

//spring加载

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>

3.在struts-config.xml中配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources />
  <form-beans />
  <global-exceptions>
   <exception key="global_error" type="java.lang.Exception" path="/common/error.jsp" scope="request"></exception> 
  </global-exceptions>
  <global-forwards>
   <forward name="global_succ" path="/common/success.jsp" />
   <forward name="global_failed" path="/common/error.jsp" />
   <forward name="global_message" path="/common/message.jsp" />
   <forward name="global_info" path="/common/info.jsp" />
  </global-forwards>
  <action-mappings />
  <message-resources parameter="com.ApplicationResources" />
 <!--
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
   -->
</struts-config>

主要配置global_exception、global_forward、message-resource等信息。

4.struts-config-pay.xml的配置如下:

 主要配置formBean和actionMapping

 

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "
http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>

  <form-beans>
  <form-bean name="loginForm"
   type="com.web.forms.UserLoginForm">
  </form-bean>
  </form-beans>

<action-mappings>

<action name="loginForm" parameter="adminlogin"
   path="/adminlogin" input="/form/adminlogin.jsp" scope="request"
   type="org.springframework.web.struts.DelegatingActionProxy"     //这里利用spring来管理struts的Action
   validate="true">
   <forward name="failure" path="/form/adminlogin.jsp" />
   <forward name="success" path="/form/index.jsp" />
   <forward name="resetpwd" path="/form/resetPwd.jsp"/>
  </action>

</action-mappings>

</struts-config>

5.然后在applicationContext中进行action的管理。applicationContext.xml配置如下:

<bean name="/adminlogin"
  class="com.web.struts.form.LoginAction">
  <property name="LoginService">
   <ref local="LoginService" />
  </property>

 

此处的name要和struts-config-pay.xml中的path对应起来,这样就实现了spring对action的管理,从而整合了struts1.3.5

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值