spring如何处理struts的Dispatchaction

来源:百度知道 编辑:UC知道 时间:2024/06/02 08:09:42
只会处理public class MyAction extends Action这种的
但是public class MyAction extends DispatchAction该怎么整合呢?

整合的话,有三种方法。
----------------------------
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,<