社区
Web 开发
帖子详情
在struts中DispatchAction的使用方法?最好有实例代码!
zuoguodang
2008-04-17 09:45:17
如题,到底对开发的时候,有什么好处么
...全文
166
6
打赏
收藏
在struts中DispatchAction的使用方法?最好有实例代码!
如题,到底对开发的时候,有什么好处么
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
小南瓜瓜
2008-04-17
打赏
举报
回复
不使用dispatchAction也可以实现的,但是要从页面上传参数,其实都是一样的原理
vbjava_zym
2008-04-17
打赏
举报
回复
同一个模块下 为了 更清晰的 把所有的功能都 整和到一起 所以可以用到它 只不过用的时候要指向一个方法在 config 中加上一个参数
firebird44
2008-04-17
打赏
举报
回复
DispatchAction 继承与Action
可以减少Action数量,使程序清晰,简洁
yangxiao_jiang
2008-04-17
打赏
举报
回复
DispatchAction是struts里面使用的,你一般不会使用这个的。
这个是能根据你的forward的路径,进行dispatch
bobor_2008
2008-04-17
打赏
举报
回复
DispatchAction类是一个抽象类,它实现了父类(Action)的execute()方法,所以它的子类就不用来实现这个方法了,只需要专注与实际操作的方法,
1.首先要一个DispatchAction的子类,它含有一些方法,login,logout,method1,
package examples;
package examples;
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的邏輯
return mapping.findForward("success");
}
public ActionForward logout(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// 進行一些Logout的邏輯
return mapping.findForward("success1");
}
public ActionForward method1(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// 進行一些method1的邏輯
return mapping.findForward("success");
}
}
一定要注意在DispatchAction中你想执行的操作,都必须要有统一的参数(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response),是一个规定.
2.接下来是配置struts-config.xml
<action path="/login" type="examples.AccountAction"
name="logonForm"
scope="request"
parameter="action"
input="/pages/dispatch1.jsp">
<forward name="success" path="/pages/success.jsp" />
</action>
<action path="/logout" type="examples.AccountAction"
name="logonForm"
scope="request"
parameter="action"
input="/pages/dispatch1.jsp">
<forward name="success1" path="/pages/success1.jsp" />
</action>
这里需要注意的就是parameter属性的值,因为这个值要和页面传来的参数对应.
3.再来看看JSP页 pages/dispatch1.jsp
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:link href="/DispathActionTest/login.do?action=login">login</html:link><br>
<html:link href="/DispathActionTest/logout.do?action=logout">logout</html:link>
这里要注意几点,首先 ?后面的KEY要和struts-config.xml中的parameter相同,还有它的VALUE要是你在action的一个方法名字,这里方法名为login, 那么在程序运行时就是调用login的操作,如果是logout,那程序就调用logout的操作.
zuoguodang
2008-04-17
打赏
举报
回复
快点回答啊
struts
中
dispatch
Action
用法
Action
Servlet根据配置的
Action
Mapping来找到对应的
Dispatch
Action
实例
,然后解析请求
中
的参数,比如`
action
`或`method`,这个参数就是用来指定要执行的子
方法
的名称。 以下是一个简单的
Dispatch
Action
使用
步骤: ...
struts
Dispatch
Action
Struts
Dispatch
Action
是一个在
Struts
框架
中
非常重要的概念,它是一种控制器组件,用于处理来自用户的请求并调度到相应的业务逻辑
方法
。在
Struts
框架
中
,
Dispatch
er
Action
是
Action
类的一个子类,它的主要作用是实现...
Dispatch
Action
实例
在
Struts
框架
中
,`
Dispatch
Action
`是一个非常重要的组件,它是
Struts
提供的一个扩展自`
Action
`类的抽象类,主要用于处理多个请求
方法
的情况。在实际的Web应用程序开发
中
,通常一个URL对应一个
Action
,而`...
利用
struts
标签,
dispatch
Action
,实现增删改查
- **配置
Action
**:在
struts
-config.xml
中
,我们需要定义
Dispatch
Action
,指定其对应的类以及各个请求参数与
方法
的映射关系。例如: ```xml <param name="operation">add ``` - **实现
Action
类**:在对应...
struts
Lookupdispath
Action
类
使用
实例
Struts
Lookup
Dispatch
Action
类是Apache
Struts
框架
中
的一种高级控制器,它扩展了`
Dispatch
Action
`类,提供了一种更加灵活的方式来处理请求映射。在
Struts
框架
中
,
Action
是业务逻辑的核心组件,负责接收HTTP...
Web 开发
81,122
社区成员
341,744
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章