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.自定义标签和信息资源整合到一个 ...
随机推荐
- ssh 通过跳板机连接到远程服务器
ssh 通过跳板机连接到远程服务器 import paramiko from sshtunnel import SSHTunnelForwarder import threading def read ...
- Java入门:基础算法之求数组元素的和
本程序计算数组中所有元素的和. 代码1:数组元素由程序内部初始化 /** * @author: 理工云课堂 * @description: 求数组元素的和 */ class SumOfArray{ p ...
- LigerUI下拉选择列表LigerComboBox中tree的节点初始化默认选中的问题
问题描述 用后台的Json传送tree的数据 前端用js方法来控制选中节点 此方法存在bug 实例: bug问题:无论设置的默认选中值是多少个,前台checkbox最多只显示选中一个,但是内容框中显示 ...
- 《剑指offer》 面试题43 n个骰子的点数 (java)
引言:写这篇文章的初衷只是想做个笔记,因为这道题代码量有点大,有点抽象,而书上并没有详细的注释.为了加深印象和便于下次复习,做个记录. 原题:把n个骰子扔到地上,所有骰子朝上一面的点数之后为s. 输入 ...
- Object-C使用类静态方法创建对象时容易内存泄露
1.所谓使用类的静态方法创建对象,就是指使用类名调用一次它的静态方法(非显式调用alloc)便可以得到一个新建的对象,比如下面两个例子: NSString* str1 = [NSString stri ...
- vue 隐藏滚动条
element-ui隐藏组件scrollbar: <el-scrollbar style="height:100%"> </el-scrollbar> 真正 ...
- Tomcat开启Debug模式
在bin/catalina.sh中添加如下行,将tomcat重启即可. 注:以下标红的7002需将其改成对象的tomcat端口即可! JAVA_OPTS=,server=y,suspend=n -Df ...
- 高性能流媒体服务器EasyDarwin
标准RTSP拉模式直播(EasyRelayModule):适合内部监控 分布式部署(EasyCMSModule):负载均衡主要是用Reids作为负载
- 20155227 2016-2017-2 《Java程序设计》第七周学习总结
20155227 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 认识时间与日期 时间的度量 世界时:在1972年引入UTC之前,GMT与UT是相同的. 国际 ...
- laravel更新某一个或几个字段
//更新会员状态status $ary_where = array(); $ary_where[] = ['id', '=', $int_id]; $result = $this->obj_ad ...