struts整合spring方法
最佳答案
整合的话,有三种方法。
----------------------------
Spring 和struts 整合的三种方式
Spring 和 struts 整合的三种方式。
1,使用Spring 的 ActionSupport
2, 使用Spring 的 DelegatingRequestProcessor 类。
3,全权委托。
无论用那种方法来整合第一步就是要为struts来装载spring的应用环境。 就是在 struts 中加入一个插件。
struts-config.xml中
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
spring 的配置文件被作为参数配置进来。这样可以省略对web.xml 文件中的配置。确保你的applicationContext.xml 在WEB-INF目录下面
1,使用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;// TODO Auto-generated method stub //获得 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");
, 1-1 无论用那种方法来整合第一步就是要为 struts 来装载 spring 的应用环境。 就是在 struts 中加入一个 插件。 1-1-1 使用 Struts 插件的方式保证先...
Spring和Struts整合_IT/计算机_专业资料。Spring和Struts整合 Spring+Struts整合三种方式方式一:通过Spring的ActionSupport类实现 方式二:通过Spring的DelegatingRequestPrSp...
spring 与 struts 整合 有3 种方法_计算机软件及应用_IT/计算机_专业资料。3种方法实现spring 与 struts 的整合spring 与 struts 整合 有 3 种方法 实质是 spri...
若存在多个不同目录 Spring 配置文件,则在中使用通配符 classpath*:beans/**/*.xml 4.Struts2 框架整合 Spring 的两种方式 单独使用 struts2 时由 Struts2 默...
第二种实现方法: 1) 业务类在Spring配置文件中配置,业务逻辑控制器类不需要配置,Struts2的Action像没有整合Spring之前一样配置,<action>的class属性指定业务逻辑...
spring2.0与struts1.x 整合三种方法_IT/计算机_专业资料。spring2.0与struts1.x 整合三种方法spring2.0 与 struts1.x 整合三种方法! 2008-09-03 10:20 1...
Spring+Struts2+Hibernate 整合在 SSH 的整合过程中添加框架的顺序并没有严格...我们只需从 ObjectFactory 类派生一个子类,覆盖示例 6 中的方法,通过 Spring ...
struts2与spring整合的原理_计算机软件及应用_IT/计算机_专业资料。Struts2 与 ...我们可以在 DefaultActionInvocation 的 createAction 方法打印一下 objectFactory 会...
Spring 整合 Struts 的两种方式的两种方式: ? struts1 加载 spring 的两种方式: 第一种: 配置加载 上下文环境,其配置方式如下: 第一种:通过 web.xml 配置加载...
Struts2 是一个 MVC 框架,是一个 web 层的解决方案。它提供了非常简单的方式来 完成与 Spring 的整合。 1. 整合思路将 Struts2 中的 Action 交给 Spring ...
热门文档