The DispatchAction class (org.apache.struts.actions.DispatchAction) provides a way to group all related functions into a single action class. It’s a useful mechanism to avoid create separate action classe for each function.

To implement this mechanism, your action class need to extends org.apache.struts.actions.DispatchAction class, this action class does not need to implement the execute() method as normal action class does. Instead, the DispatchAction class will execute the method base on the incoming request parameter – method. For example, if the parameter is “method=chinese”, then the chinese() method will be execute.

Example

A action class extends the DispatchAction, and contains four methods to set the locale into the Struts session attribute for the localization.

public class LanguageSelectAction extends DispatchAction{

	public ActionForward chinese(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception { request.getSession().setAttribute(
Globals.LOCALE_KEY, Locale.SIMPLIFIED_CHINESE); return mapping.findForward("success");
} public ActionForward english(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception { request.getSession().setAttribute(
Globals.LOCALE_KEY, Locale.ENGLISH); return mapping.findForward("success");
} public ActionForward german(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception { request.getSession().setAttribute(
Globals.LOCALE_KEY, Locale.GERMAN); return mapping.findForward("success");
} public ActionForward france(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception { request.getSession().setAttribute(
Globals.LOCALE_KEY, Locale.FRANCE); return mapping.findForward("success");
} }

This Struts html tag will execute the chinese() method.

Chinese

This Struts html tag will execute the english() method.

English

This Struts html tag will execute the german() method.

German

This Struts html tag will execute the france() method.

France

Struts DispatchAction Example的更多相关文章

  1. Struts dispatchAction

    在Struts中定义动态Action,不用定义多个Action,可以实现一个action,多个跳转. 在定义时,继承DispatchAction,并定义parameter的名字 在jsp页面选择act ...

  2. AjaxAnywhere+struts用法

    AjaxAnywhere的用法 1,简介 AjaxAnywhere被设计成能够把任何一套现存的JSP组件转换成AJAX感知组件而不需要复杂的JavaScript编码.它利用标签把Web页面简单地划分成 ...

  3. Struts – MappingDispatchAction Example

    Struts MappingDispatchAction class is used to group similar functionality into a single action class ...

  4. AjaxAnywhere的用法(FORWARD)

    AjaxAnywhere的用法   ajaxanywhere 总结:1,简介AjaxAnywhere被设计成能够把任何一套现存的JSP组件转换成AJAX感知组件而不需要复杂的JavaScript编码. ...

  5. 有关struts中DispatchAction的用法小结

       今天刚刚看了DispatchAction觉得这个东西有点意思,所以就写点东西,通过它的名字我想应该可以明白它的作用了,用于分发的Action,主要的好处是把一些功能类似的Action放到一个Ac ...

  6. Struts 1之DispatchAction

    DispatchAction是struts 1 的内置通用分发器 import org.apache.struts.actions.DispatchAction; public class UserA ...

  7. 【Struts 分派Action】DispatchAction

    LoginAction package k.action; import k.form.UserForm; import org.apache.struts.action.ActionForm; im ...

  8. Struts与Struts2的区别

    Struts与Struts2的区别 首先看一张Struts2的发展路线图:       从Struts2的发展过程来看,Struts2继承了Struts与Webwork的特性,形成了新的框架.但是它的 ...

  9. Struts核心技术简介

    Struts核心技术简介 1.Struts内部机制   Struts是一种基于MVC经典设计模式的开发源代码的应用框架,它通过把Servlet.JSP.JavaBean.自定义标签和信息资源整合到一个 ...

随机推荐

  1. 关于.Net开源并跨平台的思考

    开源的意义: 关于开源,我个人觉得有两个提高(勿喷). 一方面开源提高了生产力,另一方面开源也是信任的一种体现.为什么这么说呢,在当下的互联网时代,开源是一种核心价值观.人与人沟通交流合作之下,降低成 ...

  2. GeoDa计算全局Moran‘I

    GeoDa计算全局Moran‘I 1.导入包含数据的.shp文件 2.创建权重矩阵,点击Weight Manger,再点击Create, weights file ID variable(其中包含的数 ...

  3. 深入理解Python中的元类(metaclass)

    原文 译注:这是一篇在Stack overflow上很热的帖子.提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解.他知道这肯定和自省有关,但仍 ...

  4. oracle中所有存在不存在的用户都可以使用dba连接到数据库

    oracle中所有存在不存在的用户都可以使用dba连接到数据库及解决方式 以前一直使用conn /as sysdba连接数据库,不明白里面的意思.今天无意中使用其他的用户名密码连接到dba竟然也可以( ...

  5. Spyder code editor里的小秘密: 右侧高亮提示

    Spyder code editor里的小秘密: 右侧高亮提示 在spyder环境里, 混了那么长时间了. 可是对其代码编辑器右侧紧贴滚动条的高亮指示区, 还没有弄明白. 今天仔细研究和观察了一下, ...

  6. @Controller,@Service,@Repository,@Component详解

    @Controller 用来表示一个web控制层bean,如SpringMvc中的控制器. @Service 用来表示一个业务层bean. @Repository 用来表示一个持久层bean,即数据访 ...

  7. 【Foreign】tty的方程math [数学]

    tty的方程math Time Limit: 50 Sec  Memory Limit: 128 MB Description 给定n.m.k.p. a+b+c=n, a^2+b^2+c^2=m, a ...

  8. OI,再见

    SDOI2016 因为自己的沙茶犯了低级的沙茶错误而滚粗. day2原可以AK,却因为眼残脑残只拿到90. 由此可见,细节永远不是一个小问题. 想想过去的日子,还真是舍不得. 但过去的终将过去,未来的 ...

  9. Django 使用mysql 所遇到问题一:Error loading MySQLdb module

    在配置完mysql 的配置信息后执行 python manage.py runserver 时出现如下错误.(py3的环境) 解决 在 python2 中,使用 pip install mysql-p ...

  10. WeX5入门之HelloWorld

    学习目标:数据双向绑定 在ui2上右键 新建一个应用 然后会出现一个目录 右键hello 在创建页面 选择标准的空白模板 并起一个名 自动生成这两个文件 建立一个input组件 再建一个output组 ...