Struts hibernate Spring 整合
2008-06-14 22:50
405 查看
一、Struts 和 Spring 整合
第1步:将spring做为插件加到struts_config.xml中:
<struts-config>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
这是加载spring的context
第2步:将控制权交给Spring定制的Action处理,在struts_config.xml的配置action的type:
<action-mappings>
<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm">
<forward name="success" path="/main.jsp" />
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>
DelegatingActionProxy同样是 org.apache.struts.action.Action的一个子类,它将把调用请求转交给真正的Action实现。
第3步:在spring的配置文件applicationContext.xml中配置Action的bean
<bean name="/login" class="cn.uolee.wap.LoginAction" singleton="false">
<property name="userDAO">
<ref bean="userDAOProxy" />
</property>
</bean>
这样当用户请求login.do页面的时候,DelegatingActionProxy将在applicationContext.xml中获取真正的Action实例,并且调用Action的execute()方法。
下面是 DelegatingActionProxy的 execute方法代码:
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
//获得实际的Action实例,并将请求转交
Action delegateAction = getDelegateAction(mapping);
return delegateAction.execute(mapping, form, request, response);
}
第1步:将spring做为插件加到struts_config.xml中:
<struts-config>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
这是加载spring的context
第2步:将控制权交给Spring定制的Action处理,在struts_config.xml的配置action的type:
<action-mappings>
<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm">
<forward name="success" path="/main.jsp" />
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>
DelegatingActionProxy同样是 org.apache.struts.action.Action的一个子类,它将把调用请求转交给真正的Action实现。
第3步:在spring的配置文件applicationContext.xml中配置Action的bean
<bean name="/login" class="cn.uolee.wap.LoginAction" singleton="false">
<property name="userDAO">
<ref bean="userDAOProxy" />
</property>
</bean>
这样当用户请求login.do页面的时候,DelegatingActionProxy将在applicationContext.xml中获取真正的Action实例,并且调用Action的execute()方法。
下面是 DelegatingActionProxy的 execute方法代码:
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
//获得实际的Action实例,并将请求转交
Action delegateAction = getDelegateAction(mapping);
return delegateAction.execute(mapping, form, request, response);
}
相关文章推荐
- Spring2.5+Struts1.3.8+Jpa(Hibernate实现)整合之七
- 在进行maven+spring+struts+hibernate整合时发生class path resource [spring.xml] cannot be opened because it do
- 用maven整合struts+spring+hibernate之二 数据库生成和测试数据
- Struts Spring Hibernate 框架整合时候出现的问题
- Struts+Spring+Hibernate整合入门详解
- Struts、Spring、Hibernate之间的整合方式
- struts+hibernate+spring的整合
- (转)最新版的SSH框整合(Spring 3.1.1 + Struts 2.3.1.2 + Hibernate 4.1)
- Spring2.5+Struts1.3.8+JPA(Hibernate实现)整合之五
- Struts+Spring+Hibernate 整合笔记
- spring整合struts,hibernate annotation(pool数据池,sqlserver2005数据库)
- struts-2.3、spring2.5.6、hibernate3.3整合
- struts+hibernate+spring整合过程常见问题收集
- Struts+Spring+Hibernate/SSH整合开发详细二
- Struts、Spring、hibernate的整合
- Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2 整合总结
- Java-Spring+Struts+Hibernate-SSH框架整合02-Spring+Hibernate
- 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓