Struts2动态调用方法

本文介绍了Struts2中的动态方法调用,包括配置动态方法、通配符方法调用以及动态方法的特点。同时,文章详细讲解了返回值的配置,如name和type属性,以及dispatcher、redirect和chain类型的区别。此外,还提到了全局返回结果和动态返回结果的使用。
摘要由CSDN通过智能技术生成


========= struts2 切换到 2.3.1.2 版本 ============

动态方法调用
1. struts.xml开启动态方法
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    注意:constant 放在packge外面
    
2. 编写Action

3. 注册Action
    注册Action的时候注意不需要method属性
    
4. 访问对应action的时候在最后面加!方法名称
    http://127.0.0.1:8080/struts2_method23/userinfoAction[!add]
    http://127.0.0.1:8080/struts2_method23/userinfoAction!add
    
============== 
1. 动态方法调用
    1. <action>去掉method属性,url通过!指定具体方法
    
    注意:struts2 2.5 以后版本的配置方式有点不同
        <global-allowed-methods>regex:.*</global-allowed-methods>
    
2. 通配符方法调用

    <action name="persionAction_*" class="com.javaee.struts2.action.PersionAction" method="{1}">
        <result>/index.jsp</result>
    </action> 
    
    * 代表访问Action类中的方法
    

 

1. 方法调用

1. 默认方法

2. 自定义方法

3. 动态方法

一个Action类可以有多个业务逻辑方法,但是只需要配置一个Action标签,不需要method属性,在调用时指出Action名和业务逻辑方法。使用动态方法调用步骤如下:

  1. struts.xml 开启动态方法调用

<constant name="struts.enable.DynamicMethodInvocation" value="true" />
  1. 编写Action

  2. 注册Action

<!-- 2.5 版本后需要配置此属性才能够使用动态方法和通配符 -->
<global-allowed-methods>regex:.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值