spring+hibernate+struts 整合的三种方法,我只用第三种可以。
来源:互联网 发布:mac版电脑可以玩的网游 编辑:程序博客网 时间:2024/05/15 23:50
一.用spring的DelegatingRequestProcessor替换struts的RequestProcessor.
1)不要在web.xml中设置ApplicationContext的自动加载,在struts-config.xml中通plug-in设置.
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property value="/WEB-INF/applicationContext.xml,/WEB-INF/appContext.xml" property="contextConfigLocation" />
</plug-in>
2)在struts-config.xml中设置RequestProcessor的替换类.
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
3)不要在struts-config.xml中的<action>元素中设置action的type属性.
<action path="/login" input="/index.jsp"
validate="true" scope="request">
<forward name="forward" path="/success.jsp"></forward>
</action>
4)在applicationContext.xml或其他spring bean配置文件中设置由DelegatingRequestProcessor转发的bean,这个bean就是Action类.
<bean name="/login" class="mypack.LoginAction" singleton="false">
<property name="property1" ref="otherbean"/>
</bean>
二.使用DelegatingActionProxy,此种方法是在action中再把请求转发给定义在applicationContext.xml中的Action.
1)同第一种方法的1).
2)如果试了第一种方法,去掉struts-config.xml中的
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
元素.
3)需要在struts-config.xml中定义action的type="org.springframework.web.struts.DelegatingActionProxy".即第一种方法的3)中加入type属性.
<action path="/login" input="/index.jsp" validate="true"
scope="request" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="forward" path="/success.jsp"></forward>
</action>
4)同第一种方法的4).
三.使用Spring的ActionSupport .
Spring 的ActionSupport 继承至org.apache.struts.action.Action
ActionSupport的子类可以或得 WebApplicationContext类型的全局变量。通过getWebApplicationContext()可以获得这个变量。
这是一个 servlet 的代码:
public class LoginAction extends org.springframework.web.struts.ActionSupport { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form; //获得 WebApplicationContext 对象 WebApplicationContext ctx = this.getWebApplicationContext(); LoginDao dao = (LoginDao) ctx.getBean("loginDao"); User u = new User(); u.setName(loginForm.getName()); u.setPwd(loginForm.getPwd()); if(dao.checkLogin(u)){ return mapping.findForward("success"); }else{ return mapping.findForward("error"); } } }
applicationContext.xml 中的配置 <beans> <bean id="loginDao" class="com.cao.dao.LoginDao"/> </beans>
- spring+hibernate+struts 整合的三种方法,我只用第三种可以。
- Spring整合Struts的三种方法
- Struts+hibernate+Spring的整合方法
- 为什么Struts、Spring、Hibernate框架可以被整合的问题
- 第三篇 整合struts+spring+hibernate
- 三大框架的整合技术 SSH spring,hibernate,struts;
- struts+hibernate+spring的整合
- Struts,Hibernate,Spring的整合
- Struts、Spring、hibernate的整合
- Struts Spring Hibernate三大框架整合
- 三大框架整合struts+spring+hibernate
- spring和struts的整合的三种方式
- Spring 和struts 整合的三种方式
- Spring 和struts 整合的三种方式
- 三种整合 Struts 应用程序与 Spring 的方式
- Spring与struts 整合的三种方式
- Spring 和 struts 整合的三种方式
- 三种整合 Struts 应用程序与 Spring 的方式
- 2081 Recaman's Sequence 水题报告
- 如何实现中式报表的组名合并风格
- NetBPM的安装 -转
- BCD码介绍(转载之网络)
- 使用 AWK 來做垂直數字加總
- spring+hibernate+struts 整合的三种方法,我只用第三种可以。
- 激活 ActiveX 控件
- java web工程里混入eclipse swt代码的诡异现象
- spring+hibernate+struts 自己总结出的方法。
- 开始学习C#
- DOS下建立文件夹和超级文件夹
- 关于malloc和free
- DATEDIFF时间函数的用法
- ITIL实施不可操之过急