码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2.5动态方法调用action和使用通配符访问action

时间:2017-09-25 21:58:59      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:div   r.js   doc   print   value   配置   .config   detail   int   

【原帖地址】http://blog.csdn.net/leafage_m/article/details/54577687

 

动态方法调用Action。

这种方法,需要在struts.xml中对其进行支持:

[html] view plain copy print?
<!-- 是否开启动态方法调用 -->  
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />  

当struts.xml中的这个配置的value为true时,代表可以使用动态方法对action进行调用。

 

然后使用“actionName!methodName“,这种形式:action名字!使用的方法名字  就可以调用不同的方法了。

首先配置struts.xml 添加一个名字为:test的action:

<?xml version="1.0" encoding="UTF-8"?>    
<!DOCTYPE struts PUBLIC    
            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"    
    "http://struts.apache.org/dtds/struts-2.5.dtd">  
<struts>  
    <include file="struts-default.xml"></include>  
    <!-- 指定默认编码集 -->  
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>  
    <!-- 指定需要Struts2处理的请求后缀 -->  
    <constant name="struts.action.extension" value="do,action"></constant>  
    <!-- 设置浏览器是否缓存静态内容,开发阶段应关闭,生产阶段打开,默认为打开 -->  
    <constant name="struts.serve.static.browserCache" value="false"></constant>  
    <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认为false,开发阶段应打开 -->  
    <constant name="struts.configuration.xml.reload" value="true"></constant>  
    <!-- 开发模式下使用,可以打印出更详细的错误信息 -->  
    <constant name="struts.devMode" value="true"></constant>  
    <!-- action全部用注解进行配置 -->  
  
    <!-- 是否开启动态方法调用 -->  
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />  
    <!--添加包 -->  
    <package name="hellostruts" extends="struts-default">  
        <action name="test" class="hellostruts.test">  
            <result name="success">success.jsp</result>  
            <result name="error">error.jsp</result>  
            <allowed-methods>login,print</allowed-methods>  
        </action>  
    </package>  
</struts>    

注意:在Struts2.5中必须为想要支持动态访问的method在<allowed-methods>标签中进行描述。

[html] view plain copy print?
<allowed-methods>login,print</allowed-methods>  

 

Struts2.5动态方法调用action和使用通配符访问action

标签:div   r.js   doc   print   value   配置   .config   detail   int   

原文地址:http://www.cnblogs.com/yyxxn/p/7593792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!