Struts DispatchAction Example
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的更多相关文章
- Struts dispatchAction
在Struts中定义动态Action,不用定义多个Action,可以实现一个action,多个跳转. 在定义时,继承DispatchAction,并定义parameter的名字 在jsp页面选择act ...
- AjaxAnywhere+struts用法
AjaxAnywhere的用法 1,简介 AjaxAnywhere被设计成能够把任何一套现存的JSP组件转换成AJAX感知组件而不需要复杂的JavaScript编码.它利用标签把Web页面简单地划分成 ...
- Struts – MappingDispatchAction Example
Struts MappingDispatchAction class is used to group similar functionality into a single action class ...
- AjaxAnywhere的用法(FORWARD)
AjaxAnywhere的用法 ajaxanywhere 总结:1,简介AjaxAnywhere被设计成能够把任何一套现存的JSP组件转换成AJAX感知组件而不需要复杂的JavaScript编码. ...
- 有关struts中DispatchAction的用法小结
今天刚刚看了DispatchAction觉得这个东西有点意思,所以就写点东西,通过它的名字我想应该可以明白它的作用了,用于分发的Action,主要的好处是把一些功能类似的Action放到一个Ac ...
- Struts 1之DispatchAction
DispatchAction是struts 1 的内置通用分发器 import org.apache.struts.actions.DispatchAction; public class UserA ...
- 【Struts 分派Action】DispatchAction
LoginAction package k.action; import k.form.UserForm; import org.apache.struts.action.ActionForm; im ...
- Struts与Struts2的区别
Struts与Struts2的区别 首先看一张Struts2的发展路线图: 从Struts2的发展过程来看,Struts2继承了Struts与Webwork的特性,形成了新的框架.但是它的 ...
- Struts核心技术简介
Struts核心技术简介 1.Struts内部机制 Struts是一种基于MVC经典设计模式的开发源代码的应用框架,它通过把Servlet.JSP.JavaBean.自定义标签和信息资源整合到一个 ...
随机推荐
- NFS服务端+客户端配置
一.Server端配置 1.下载rpcbind和nfs #yum install -y rpcbind nfs-utils 2.创建共享文件并授权 创建共享文件夹 #mkdir /server-nfs ...
- P1850 换教室
P1850 换教室 现在有一张图, 有 \(v <= 300\) 个节点 你需要从 \(c_{1}\) 到 \(c_{2}\) 到 \(c_{n} (n <= 2000)\) 现在你有 \ ...
- JavaScript中的arguments详解
1. arguments arguments不是真正的数组,它是一个实参对象,每个实参对象都包含以数字为索引的一组元素以及length属性. (function () { console.log(ar ...
- SXOI2018 游记
noilinux@Capella:~$ cd /Memories/ noilinux@Capella:/Memories$ rm *SXOI* rm:是否删除有写保护的普通文件 "SXOI2 ...
- github 新创建repositories
1. 在github上新建repo 2. 找到改repo的地址,用命令git clone https://...., 拉取到本地 3. 打开一个单独的窗口,打开此文件夹 4. 创建自己的python ...
- 平铺式窗口管理器 Musca 初体验
作者: 吴吉庆 Version: 1.0 release: 2009-11-04 update: 2009-11-04 为什么用平铺式窗口管理器? 什么是平铺式窗口管理器(tiling window ...
- URL访问 和命名规范
手册:http://v9.help.phpcms.cn/html/2010/structure_0928/71.html http://yourdomain.com/index.php?m=conte ...
- 【leetcode 简单】 第七十七题 单词模式
给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式. 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向 ...
- 莫队-小Z的袜子
----普通莫队 首先清楚概率怎么求假设我们要求从区间l到r中拿出一对袜子的概率sum[i]为第i种袜子在l到r中的数量 $$\frac{\sum_{i=l}^{r} {[sum[i] \times ...
- Python练习-生成器-一个生成器被坑的体无完肤
代码如下,尽可能独立阅读: # 编辑者:闫龙 from urllib.request import urlopen #导入一个包,这就是egon留的一个坑 def get(url):#这是为了保证题目 ...