struts 1.x spring 整合
来源:互联网 发布:临汾行知学校 编辑:程序博客网 时间:2024/05/18 04:00
<struts-config>
<data-sources />
<form-beans>
<form-bean name="studentForm" type="com.ssh.form.StudentForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/student"
type="org.springframework.web.struts.DelegatingActionProxy"
parameter="cmd"
name="studentForm"
scope="request">
<forward name="loadadd" path="/student_add.jsp" />
<forward name="add" path="/student.do?cmd=list" redirect="true" />
<forward name="loadedit" path="/student_edit.jsp" />
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:applicationContext-*.xml"/>
</plug-in>
</struts-config>
applicationContext.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 与struts的整合 -->
<bean name="/student" class="com.ssh.action.StudentAction">
<property name="studentDao" ref="studentDao" />
</bean>
</beans>
需要说明的是,由于spring dtd规定id不能有"/",所以我们用name定义path,并且,spring bean的name要和struts-config.xml中的path一致
使用DelegatingActionProxy的好处就在于你可以用不用任何spring特定的类编写Struts Action,这个方法也有不足之处,就是不太直观,因为所有路径都映射到同一个类了
对于这种情况,spring也有解决方法,就是使用请求委托
首先,为struts-config.xml增加controller
<!-- 使用请求委托 -->
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
然后,修 改我们的path定义位 <action path="/listStudentAction" type="action.ListStudentActionAction"/>
这样,又和我们单独使用struts的时候一样了,但内部还是让spring取代理我们的真正的action
需要说明的是,这里的type其实是个摆设,完全可以使用 <action path="/listStudentAction"/>,写上是为了解决我们上面提到的“不够直观的”的问题
- struts 1.x spring 整合
- 1.Spring整合struts
- 基于Struts 1.x + Hibernate 3.x + Spring 2.x 整合
- Struts2.x+Spring3.x+Hibernate4.x 整合(二)Struts+Spring 整合
- flex3+struts 1.3+spring+ibatis 2.x整合代码实例
- flex3+struts 1.3+spring+ibatis 2.x整合代码实例
- 基于Struts 2.x + Spring 2.x + Hibernate 3.x整合开发
- struts整合spring整合hibernate
- 整合 struts spring hibernate
- Spring , Struts整合方法
- 整合Struts 与Spring
- 整合Struts 与Spring
- struts整合spring
- struts+spring+hibernate整合
- struts,hibernate,spring整合
- 整合 Struts 和 Spring
- struts+spring+hibernate整合
- struts+spring+hibernate整合
- “假载”(hack-attach)受损的数据库
- 工作中最常用的数据库
- EL学习笔记
- IIS下部署WCF
- 天气晴好
- struts 1.x spring 整合
- delegate和event的区别
- IPv6和IPv4对应表
- glib库hash表GHashTable
- Android 短信 彩信 wap push的接收
- Bigtable:一个分布式的结构化数据存储系统
- SQL 语句
- SQL Server中部分未公开的存储过程
- Java开发中的命名规范