手机版
你好,游客 登录 注册
背景:
阅读新闻

Struts2为应用指定多个配置文件和动态方法调用以及通配符的使用方法

[日期:2012-02-06] 来源:Linux社区  作者:a352193394 [字体:大 中 小]
如果不指定则调用默认的execute方法,但是你可以在浏览器的地址栏使用这个样的地址请求方式来进行调用addUI这个方法,具体地址如下

http://localhost:8080/Struts2/test/helloworld!addUI.action

就是在后面加上感叹号和具体需要调用的方法名称,当然了,struts的文档不推荐使用这种方式,所以我们可以在struts.xml文件an里面通过使用静态常量的方式来指定禁止使用这样的动态方法调用

[java]
  1. ### Set this to false if you wish to disable implicit dynamic method invocation  
  2. ### via the URL request. This includes URLs like foo!bar.action, as well as params  
  3. ### like method:bar (but not action:foo).  
  4. ### An alternative to implicit dynamic method invocation is to use wildcard  
  5. ### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">  
  6. struts.enable.DynamicMethodInvocation = true  
将这个参数置为false就可以禁止,那么我们将使用下面这样推荐的通配符方法来进行调用,只需要在Action的配置文件里面这样写就可以

[java]
  1. <package name="bird" namespace="/test" extends="struts-default">  
  2.     <action name="helloworld_*" class="com.bird.action.HelloWorld" method="{1}">  
  3.       
  4.         <result name="success">/WEB-INF/jsp/hello.jsp</result>  
  5.     </action>  
  6. </package>  
在actionNamn后面加上星号,然后method是大括号加上1,这个1代表第一个星号,那么我们下面再访问的地址就可以这样写

http://localhost:8080/Struts2/test/helloworld_addUI.action

这样使用通配符就可以访问addUI这个方法了。推荐使用这样的方式哦

linux
相关资讯       Struts  Struts2 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款