原文  http://blog.csdn.net/woshixuye/article/details/7734482

首先我们有一个Action——UserAction

public class UserAction extends ActionSupport 

    public String add() 
    { 
        return "add"; 
    }

public String modify() 
    { 
        return "modify"; 
    } 
}

1 指定method

<package name="user" namespace="/userPath" extends="struts-default"> 
   <action name=" userAdd " class="com.xy.UserAction" method="add"> 
    <result name="add">add.jsp</result> 
   </action> 
   <action name=" userModify " class="com.xy.UserAction" method="modify"> 
    <result name="modify">modify.jsp</result> 
   </action> 
</package>

路径: 
userPath/userAdd 
userPath/userModify

特点: 
不灵活,CRUD四个操作就要配4个action。

2 动态方法调用DMI(Dynamic Method Invocation)

<package name="user" namespace="/userPath" extends="struts-default"> 
   <action name="user" class="com.xy.UserAction"> 
    <result name="add">add.jsp</result> 
 <result name="modify">modify.jsp</result> 
   </action> 
</package>

路径: 
userPath/user!add 
userPath/user!modify

特点: 
灵活。只要指定不同的方法就可以做不同的操作。

3 通配符

<package name="all" namespace="/" extends="struts-default"> 
   <action name="*_*" class="com.xy.{1}Action" method="{2}"> 
 <result name="add">{1}_add.jsp</result> 
 <result name="modify">{1}_modify.jsp</result> 
   </action> 
</package>

路径: 
User_add 
User_modify

特点: 
更加灵活。整个项目甚至只要配一个总的action。是指定方法的一个特殊的用法。不过我觉得用DMI可以将每个模块分的清楚。

推荐的方法是动态调用,也就是DMI.

注意的问题:

1.比如在地址栏中输入URL:http://localhost:8080/struts2/front/helloword!add

但是:如果这样输入的话,会报错(There is no Action mapped for namespace [/front] and action name [helloword!add()] associated with context path [/Struts2_10003].)
因为:struts2中默认不允许使用DMI

所以:需要在配置文件中打开: <constant name="struts.enable.DynamicMethodInvocation" value="true"/>这样大家在地址栏动态输入就可以得到预期的页面

2.如果想要利用DMI的方式传递参数的话:userPath/user!add?flag=true

最新文章

  1. Kooboo CMS技术文档之五:站点配置管理
  2. 《C#本质论》读书笔记(18)多线程处理
  3. Centos7设置关闭防火墙
  4. usb中的传输模式
  5. mysql的卸载方法
  6. 抽取的BaseFragment和LoadingPage
  7. C语言 memset函数盲点
  8. UVa1161 Objective: Berlin(最大流)
  9. centos6.4 无法进入图形界面的问题及解决
  10. 【转载】C#之int与Java之Integer的区别
  11. entity framework 查询
  12. PC-ADSL开机自动拨号方法
  13. Jenkins 七: 部署到Tomcat
  14. 去掉ILDasm的SuppressIldasmAttribute限制
  15. 使用非 GUI 模式运行 JMeter 压力测试
  16. 运维开发工程师 面试题 shell编程
  17. Python Django的生产部署方式
  18. MonoBehaviour介绍(Unity3D开发之一)
  19. Mac App开发
  20. PHP+ffmpeg+nginx的配置实现视频转码

热门文章

  1. PHP获取二维数组中的指定若干列【同array_column】
  2. bzoj 刷水
  3. HDU2818 并查集
  4. HDU 2202 计算几何
  5. 【转】最大流EK算法
  6. 四则运算项目git统计
  7. CQOI 2016 k远点对
  8. ABP理论学习之导航(Navigation)
  9. C#刨根究底:《你必须知道的.NET》读书笔记系列
  10. 大白话讲解Promise(三)搞懂jquery中的Promise