spring整合struts---个人笔记
来源:互联网 发布:康巴藏刀淘宝店 编辑:程序博客网 时间:2024/04/30 07:26
spring+struts的集成(第一种集成方案)
原理:在Action中取得BeanFactory对象,然后通过BeanFactory获取业务逻辑对象
1、spring和struts依赖库配置
* 配置struts
--拷贝struts类库和jstl类库
--修改web.xml文件来配置ActionServlet
--提供struts-config.xml文件
--提供国际化资源文件
* 配置spring
--拷贝spring类库
--提供spring配置文件
2、在struts的Action中调用如下代码取得BeanFactory
BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
or BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-beans.xml");
3、通过BeanFactory取得业务对象,调用业务逻辑方法
spring+struts的集成(第二种集成方案)
原理:将业务逻辑对象通过spring注入到Action中,从而避免了在Action类中的直接代码查询
1、spring和struts依赖库配置
* 配置struts
--拷贝struts类库和jstl类库
--修改web.xml文件来配置ActionServlet
--提供struts-config.xml文件
--提供国际化资源文件
* 配置spring
--拷贝spring类库
--提供spring配置文件
2、因为Action需要调用业务逻辑方法,所以需要在Action中提供setter方法,让spring将业务逻辑对象注入过来
3、在struts-config.xml文件中配置Action
* <action>标签中的type属性需要修改为org.springframework.web.struts.DelegatingActionProxy
DelegatingActionProxy是一个Action,主要作用是取得BeanFactory,然后根据<action>中的path属性值
到IoC容器中取得本次请求对应的Action
4、在spring配置文件中需要定义struts的Action,如:
<bean name="/login" class="com.bjsxt.usermgr.actions.LoginAction" scope="prototype">
<property name="userManager" ref="userManager"/>
</bean>
* 必须使用name属性,name属性值必须和struts-config.xml文件中<action>标签的path属性值一致
* 必须注入业务逻辑对象
* 建议将scope设置为prototype,这样就避免了struts Action的线程安全问题
web.xml加入:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
struts-config.xml加入:
<action-mappings>
<action path="/logininput" forward="/login.jsp"></action>
<action path="/login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm" scope="request">
<forward name="success" path="/success.jsp" />
</action>
</action-mappings>
applicationContext.xml加入:
<bean id="userService" class="com.jxdb.service.UserServiceImpl"/>
<bean name="/login" class="com.jxdb.struts.action.LoginAction" scope="prototype">
<property name="userService" ref="userService"/>
</bean>
- spring整合struts---个人笔记
- Struts+Spring+Hibernate整合笔记
- Struts+Spring+Hibernate 整合笔记
- 初试Struts+Spring+Hibernate整合笔记
- [转]Struts+Spring+Hibernate整合笔记
- struts与spring整合学习笔记
- Struts 2 + Spring 3 + Hibernate 整合笔记
- 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整合
- native2ascii
- Cannot load JDBC driver class 'oracle.jdbc.drive
- 如何注册国外主机和域名,更重要的是如何支付,paypal如何支付
- uclinux-2008R1.5-RC3(bf561)到VDSP5的移植(77):No usable address families found.
- ejb的client不能运行的问题+ejb接口中删除操作的参数
- spring整合struts---个人笔记
- SIF如何创建一个安全上下文学习
- Vista系统无法访问Samba共享目录
- Iterator(迭代器)的一般用法
- 如何进行软件需求分析
- 网站中文件或图片的路径问题
- Delphi面向对象学习随笔三:overload与override
- 在VC++中自定义消息
- [TEST]无默认构造函数类的初始化及容器操作