spring整合Struts的三种方式,及优缺点
来源:互联网 发布:扫描仪ocr软件下载 编辑:程序博客网 时间:2024/06/05 02:06
2010-04-04
前提:必须首先在struts框架中注册Spring
在struts-config.xml中的添加一个spring的插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="spring的xml文件的路径"
/>
</plug-in>
三种实现方式:
****1 Action===>org.springframework.web.struts.ActionSupport
同时覆盖ActionSupport的execute方法
获取spring注入的bean:
ActionSupport.getWebApplicationContext():ApplicationContext
ApplicationContext.getBean("dao")
缺陷:
1)将struts的API和Spring的API耦合在一起
2)struts的动作不在spring的管理之下,spring的优势根本没用到
****2 1)直接继承struts中的Action,将所有需要的对象,交由spring注入。即在action中提供需要的属性声明和其set方法。
2)在Struts-config.xml中使用代理org.springframe.web.struts.DelegatingActionProxy,替代原来的Action.
<action path="/add" type="...DelegatingActionProxy">
<forward.....>
</action>
3) 在spring的配置文件中,需要额外提供具体目标Action和页面中发送到请求的对应关系。以及action需要spring注入的属性
<bean name="和struts-config.xml中的path的值一样" class="具体的目标action">
<property name="dao">
<ref local="dao">
</property>
</bean>
优势:
很好的发挥了spring的Ioc和Aop
****3 1) 首先使用org.springframework.web.struts.DelegatingRequestProcessor替换struts框架中的原有的RequestProcessor
2)直接继承struts中的Action,将所有需要的对象,交由spring注入。即在action中提供需要的属性声明和其set方法。
3)在Struts-config.xml中使用原有的action
<action path="/add" >
<forward.....>
</action>
4)在spring的配置文件中,需要额外提供具体目标Action和页面中发送到请求的对应关系。以及action需要spring注入的属性
<bean name="和struts-config.xml中的path的值一样" class="具体的目标action">
<property name="dao">
<ref local="dao">
</property>
</bean>
缺陷:
1 可读性、维护性较差
2 灵活性较差
异常分类:
运行时异常(已检查异常 FileNotFoundException)
要求必须处理(捕获、抛出)
非运行时异常(未检查异常 NullPointerException)
Spring中的异常是org.springframework.dao.DataAccessException
- spring整合Struts的三种方式,及优缺点
- spring和struts的整合的三种方式
- Spring整合Struts三种方式
- Struts整合Spring三种方式
- Spring 和struts 整合的三种方式
- Spring 和struts 整合的三种方式
- 三种整合 Struts 应用程序与 Spring 的方式
- Spring与struts 整合的三种方式
- Spring 和 struts 整合的三种方式
- 三种整合 Struts 应用程序与 Spring 的方式
- Spring 和 struts 整合的三种方式。
- Spring 和 struts 整合的三种方式
- 三种整合 Struts 应用程序与 Spring 的方式
- 三种整合 Struts 应用程序与 Spring 的方式
- spring整合struts的三种方式(不错)
- Spring 和struts 整合的三种方式
- Spring 和struts 整合的三种方式
- Spring 和struts 整合的三种方式
- Android自定义View实例AnalogClock源码
- 世界坐标系到UVN Camera模型视图坐标系的转换公式的推导
- A big shift
- A Magical Potion
- pku 2513 Colored Sticks 欧拉通路问题
- spring整合Struts的三种方式,及优缺点
- 事件基础知识
- C题3只哟,,= =
- spring整合hibernate的两种方式
- Matlabz字符串转换(ZZ)
- 读取Properties文件的六种方法
- 浅析如何用C#.NET做屏幕截图软件以及注册全局快捷键(上)1
- securitytube.net security video update
- Matlab保存图片(ZZ)