惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

博客园 - Have a try

java的一些命名规则 分页-数据前序号显示的问题 接口 java.sql.Statement(附网址,不错!) Java StringBuffer类常用方法简介 SQL2000附加SQL2005数据具体方法(转) B/S系统权限控制的一种简单方法(转) JSP实现静态页生成的例子 JSP生成静态页原理(转) js日历超漂亮 一个js写的桌面倒计时(请高手帮忙改一下) 在使用struts遇到的一个问题 HQL语句大全(转) Spring框架的一些基础知识 配置Hibernate容易产生的错误 sql常用的函数 sql数据操作语句(还有例子哦) java.util.Date和java.sql.Date的区别及应用 接口的意义(转) smalldatetime和datetime的区別
DispatchAction学习
Have a try · 2008-04-11 · via 博客园 - Have a try

DispatchAction继承自Action类,它是一个抽象类,封装了一 些基础方法,来解决使用一个Action处理多个操作的能力,这就是DispatchAction最大的用途,它可以帮助我们用一个Action类,封装 一套类似的操作方法,节省了类的数目,同时也减轻了后期维护的困难。

DispatchAction中主要包括一下几个方法:

<其实是用反射>

protected ActionForward dispatchMethod
protected java.lang.reflect.Method
getMethod
protected java.lang.String getMethodName

DispatchAction在配置上于标准的Action稍有不同,就是要在Action配置中多一个parametr属性,这个属性将指导DispatchAction找到对应的方法,例如这样配置:

<action path="/saveSubscription"
       
type="org.apache.struts.actions.DispatchAction"
       name="subscriptionForm" scope="request" input="/subscription.jsp"   
       
parameter="method"/>

parameter的属性值是可以任意起的,只要你记得在传参数的时候统一就可以了。比如我写了一个类似这样的Action,它继承自 DispatchAction类,包含了三个操作方法,有Add(),Update(),Delete()。当我想要调用这个Action的Update 操作时,提交的URL应该类似这样的:

http://localhost:8080/myapp/saveSubscription.do?method=update

就是这么简单,不过非常方面我们程序员了,开发中我感觉的确省了好多代码,至少以前的三个类文件变成了现在一个类了,而且在后期维护的时候感觉也是方便很多。

需要注意的是:在调用DispatchAction的时候method参数是不能为空的,如果空,DispatchAction会调用unspecified方法并抛出异常。