使用DispatchAction类,为你的系统减肥!
来源:互联网 发布:linux文件权限777 编辑:程序博客网 时间:2024/04/28 22:06
在Struts中你要尽可能的不用Action类,因为他们让你的项目变得臃肿,你可以使用org.apache.struts.actions.DispatchAction类来完成业务逻辑所需要的相关操作集中到一个Action类中,在继承DispatchAction后,你不再是重新定义execute()方法,而是编写你自己的业务方法,execute()方法在DispatchAction抽象类定义。
例如我们可以继承DispatchAction来定义一个AccountAction,在当中集中管理一些与账号相关的操作,如下:
package onlyfun.caterpillar;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.*;
public class AccountAction extends DispatchAction {
public ActionForward login(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception { // login相关的操作 ...... }
public ActionForward logout(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception { // logout相关的操作 ...... }
public ActionForward method1(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception { // method1相关的操 ...... } .....}
我们不再重新定义execute()方法,而是定义我们自己的login()、logout()等方法,这些方法接收与execute()相同的参数,并且也传回ActionForward对象。使用DispatchAction时,我们要在struts-config.xml定义:
path="/account"
type="onlyfun.caterpillar.AccountAction"
parameter="method"
name="userForm">
name="greeting"
path="/login/greeting.jsp"/>
主要就是在parameter的属性上,我们指定以method请求参数来指定我们所要使用的方法,例如下面的网址将会执行AccountAction的login()方法:http://localhost:8080/HelloStruts/account.do?method=login&name=caterpillar&password=1234注意在请求参数中,我们包括了method=login来指定执行login()方法,同样的,如果你要执行logout()方法,则如下http://localhost:8080/HelloStruts/account.do?method=logout
转自:http://www.yourblog.org/data/20055/265266.html
- 使用DispatchAction类,为你的系统减肥!
- 使用DispatchAction类,为你的系统减肥!
- 使用DispatchAction类,为系统减肥!
- 使用DispatchAction类,为系统减肥!
- 使用DispatchAction类,为系统减肥
- 为你的linux虚拟机减减肥
- 为windows2003系统减肥
- Struts : DispatchAction 的使用
- DispatchAction的使用
- DispatchAction 的使用
- 如何为你的数据库事务日志减肥?
- [转]为windows2003系统减肥
- Struts中DispatchAction的使用.
- struts中DispatchAction的使用
- DispatchAction和ForwardAction的使用
- 使用这些提示,帮助你的减肥计划
- 自己动手,给系统减肥,你也行!
- DispatchAction类
- IT工程师必看的十条建议
- AIX系统编译问题
- Android 2.0 源码发布,已经成功移植到 HTC G1
- 参考文献著录格式(转自GB7714顺序编码制格式)
- 爱与金钱
- 使用DispatchAction类,为你的系统减肥!
- 针对java画面闪烁
- 業務効率を落とさないワークシェアリングとは
- 关于jdk7中的新语法带String的switch
- DWR获取request,response,session值
- 可怜的Sun公司,因为收购了MySQL,想卖自己都卖不了了
- 图片与二进制流之间的转换
- 我很惊讶大学生找工作要问家长 - 李开复
- 图