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.自定义标签和信息资源整合到一个 ...
随机推荐
- configServer的高可用
1.利用RabbitMQ或者是Kafka来搭建集群. 2.利用nginx来进行 3.利用Eureka来搭建
- Python【第三方模块&标准模块】
模块: 模块其实就是一个python文件 1.标准模块.标准包 #python自带的这些模块,直接import就能用的 import string,random,datetime,os,json 2. ...
- 查看oracle数据库编码:
1.客户端编码 查看方法:打开数据库所在服务器的注册表(在运行窗口中输入regedit打开)HKEY_LOCAL_MACHINE->SOFTWARE->ORACLE->HOME0-& ...
- Spring和springmvc父子容器注解扫描问题详解
一.Spring容器和springmvc容器的关系如下图所示: Spring和springmvc和作为两个独立的容器,会把扫描到的注解对象分别放到两个不同的容器中, Springmvc容器是spr ...
- java 创建最大堆
最大堆的性质是除了根节点之外的所有节点(i)都需要满足A[PARENT(i)]>A[i],即其对应节点值小于其父节点对应值. 下面实现以数组int []a构建最大堆. public class ...
- 【leetcode 简单】 第七十一题 二叉树的所有路径
给定一个二叉树,返回所有从根节点到叶子节点的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 输入: 1 / \ 2 3 \ 5 输出: ["1->2->5", ...
- vue_表单_组件
表单.组件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- [转]caffe中solver.prototxt参数说明
https://www.cnblogs.com/denny402/p/5074049.html solver算是caffe的核心的核心,它协调着整个模型的运作.caffe程序运行必带的一个参数就是so ...
- 20165230 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20165230 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩: 指 ...
- CentOS配置163yum源
1.下载repo文件 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 2.备份并替换系统的repo文件 [root@localhost ...