Struts DispatchAction Sample

wty814022051 2010-04-24 12:18:19
DispatchAction Class

DispatchAction provides a mechanism for grouping a set of related functions into a single action, thus eliminating the need to create seperate actions for each functions. In this example we will see how to group a set of user related actions like add user, update user and delete user into a single action called UserAction.

The class UserAction extends org.apache.struts.actions.DispatchAction. This class does not provide an implementation of the execute() method as the normal Action class does. The DispatchAction uses the execute method to manage delegating the request to the individual methods based on the incoming request parameter. For example if the incoming parameter is "method=add", then the add method will be invoked. These methods should have similar signature as the execute method.

01.public class UserAction extends DispatchAction {
02.
03. private final static String SUCCESS = "success";
04.
05. public ActionForward add(ActionMapping mapping, ActionForm form,
06. HttpServletRequest request, HttpServletResponse response)
07. throws Exception {
08. UserForm userForm = (UserForm) form;
09. userForm.setMessage("Inside add user method.");
10. return mapping.findForward(SUCCESS);
11. }
12.
13. public ActionForward update(ActionMapping mapping, ActionForm form,
14. HttpServletRequest request, HttpServletResponse response)
15. throws Exception {
16. UserForm userForm = (UserForm) form;
17. userForm.setMessage("Inside update user method.");
18. return mapping.findForward(SUCCESS);
19. }
20.
21. public ActionForward delete(ActionMapping mapping, ActionForm form,
22. HttpServletRequest request, HttpServletResponse response)
23. throws Exception {
24. UserForm userForm = (UserForm) form;
25. userForm.setMessage("Inside delete user method.");
26. return mapping.findForward(SUCCESS);
27. }
28.}
If you notice the signature of the add, update and delete methods are similar to the execute method except the name. The next step is to create an action mapping for this action handler. The request parameter name is specified using the parameter attribute. Here the request parameter name is method.

1.<action-mappings>
2. <action input="/index.jsp" parameter="method" name="UserForm" path="/UserAction" scope="session" type="com.vaannila.UserAction">
3. <forward name="success" path="/index.jsp" />
4. </action>
5.</action-mappings>
Now lets see how to invoke a DispatchAction from jsp. We have a simple form with three buttons to add, update and delete a user. When each button is clicked a different method in UserAction class is invoked.

01.<html>
02.<head>
03.<script type="text/javascript">
04.function submitForm()
05.{
06.document.forms[0].action = "UserAction.do?method=add"
07.document.forms[0].submit();
08.}
09.</script>
10.</head>
11.<body>
12.<html:form action="https://youtubeproxy.org/default.aspx" >
13.<table>
14.<tr>
15. <td>
16. <bean:write name="UserForm" property="message" />
17. </td>
18.</tr>
19.<tr>
20. <td>
21. <html:submit value="Add" onclick="submitForm()" />
22. </td>
23.</tr>
24.<tr>
25. <td>
26. <html:submit property="method" value="update" />
27. </td>
28.</tr>
29.<tr>
30. <td>
31. <html:submit property="method" >delete</html:submit>
32. </td>
33.</tr>
34.</table>
35.</html:form>
36.</body>
37.</html>
Now consider the update and the delete button. The request parameter name specified in the action handler is "method". So this should be specified as the property name for the submit button. The name of the method to be invoked and the value of the button should be the same. So when the button is clicked the corresponding method in the UserAction will be called. The delete button shows an alternate way to specify the value of the button.

Here the main constraint is the method name and the button name should be same. So we can't have an update button like this "Update". Inorder to avoid this you can call a javascript function on click of the button. Specify the action and submit the form from javascript. In this way we can have a different button name and method name. On click of the Add button the action value is set to "UserAction.do?method=add" and the form is submitted from javascript.
...全文
108 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
WinDirStat - Directory Statistics
Copyright (c) 2003-2005 Bernhard Seifert. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Shows where all your disk space has gone, and helps you clean it up.

You know the problem: The hard disk is almost full, and you don't know, where the big files actually are lying, which occupy all the space. They may well be hidden in sub-sub-directories. To find out this by means of the Windows Explorer, is tiring: you would have to expand and collapse directories over and over or view the "Properties" of the directories, which always count just the size of a single subtree. It's hard to form a mental image of the hard disk usage in this way. This is where WinDirStat helps.

On start up WinDirStat opens the Select Drives Dialog. Press the OK button.

Then WinDirStat reads in the whole directory tree once (this can last some minutes depending on the hard disk size) and then presents it in three useful views:

WinDirStat
Directory List Extension List
Treemap

The views are coupled with each other.

You can clean up the hard disks with several Cleanups.

The views and the User Defined Cleanups can be configured according to your personal needs.

Sorting

Legend

Frequently Asked Questions

Limits

Deinstallation

GNU Free Documentation License
真哥哥 2010-04-24
  • 打赏
  • 举报
回复

。。。。。。。
。。。。。
wty814022051 2010-04-24
  • 打赏
  • 举报
回复
刚刚开始学struts,这些例子对你或许有些用
内容概要:本文围绕基于BP神经网络的水质预测方法展开,详细介绍了利用Matlab实现数据驱动的BP神经网络模型构建过程,旨在通过对水质参数(如pH、溶解氧、浊度等)的历史数据进行训练,实现对未来水质变化趋势的科学预测。该方法突出“数据驱动”特性,强调模型在环境工程与智能算法融合领域的应用价值,适用于科研复现与学术论文撰写,尤其适合作为EI/SCI级别论文中的算法模型支撑。配套资源包含完整的Matlab代码、实验数据及仿真模型,便于用户直接运行、复现结果并进行二次开发与拓展应用。; 适合人群:具备一定编程基础,熟悉Matlab编程环境,从事环境科学、水利工程、智能算法应用等相关领域研究,工作或学习年限在1-3年的科研人员或研究生。; 使用场景及目标:①利用BP神经网络对水质指标进行时序预测,评估水体污染发展趋势;②构建水环境保护与治理的智能决策支持系统;③在撰写EI/SCI论文时作为核心算法模型进行复现与对比实验,提升研究成果的可信度与创新性; 阅读建议:此资源以数据驱动为核心,建议读者结合所提供的Matlab代码与真实水质数据集开展实践操作,重点关注网络结构设计、训练参数调优、过拟合防范及预测结果可视化分析流程,同时可尝试将模型迁移至其他环境预测场景以增强泛化能力与科研适应性。
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧