struts2 中使用DMI(动态调用方法)方式配置action

本文介绍Struts2框架中动态方法调用(DMI)的两种配置方式及如何启用该功能。通过示例展示了如何配置struts.xml文件以实现特定Action方法的调用,并说明了新版Struts2默认关闭DMI功能及其开启方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、使用 "!"方式,即 action名称 ! 方法名称

struts.xml 配置

    <package name="user" namespace="/user" extends="struts-default">
        <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
            <result>/user_add_success.jsp</result>
        </action>
    </package>

Action:

package com.bjsxt.struts2.user.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
    
    private static final long serialVersionUID = -1735844624241755443L;

    public String add(){
        System.out.println(1341234);
        return SUCCESS;
    }
}

访问路径:http://localhost:8080/Struts2_0500_ActionMethod/user/user!add

2、新版的Struts2(具体从哪个版本起忘了),默认关闭DMI功能。需要在struts.xml 中打开:

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

转载于:https://www.cnblogs.com/ShawnYang/p/6628510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值