struts2-10动态方法调用和使用通配符定义action

动态方法的调用:
如果action中存在多个方法时,可以使用(!+方法名)调用指定的方法。如下:

package com.gz.action;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class HelloWorldAction {

    private String mes;
    private String userName;

    public String getMessage() {
        return mes;
    }
    public String execute() throws UnsupportedEncodingException {
        mes = "hello world!";
        this.userName = URLEncoder.encode("你好,世界!","UTF-8");//进行编码
        return "success";
    }
    public String addGlob() {
        return "message";
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
}

假如访问上面action的URL路径为:/struts/test/helloworld.action,要访问action中的addGlob()方法,可以这样调用:

/struts/test/helloworld!addGlob.action

如果不想使用动态方法调用,则可以通过常量struts.enable.DynamicMethodInvocation关闭动态方法调用。

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

使用通配符定义action:

<package name="hello" namespace = "/test" extends = "struts-default">
        <action name = "helloworld_*" class = "com.gz.action.HelloWorldAction" method = "{1}">
            <result name = "success">/WEB-INF/test/message.jsp</result>
        </action>
    </package>
public String execute() throws UnsupportedEncodingException {
        mes = "hello world!";
        this.userName = URLEncoder.encode("你好,世界!","UTF-8");//进行编码
        return "success";
    }
    public String addGlob() {
        return "message";
    }

访问addGlob()方法,可以通过这样的URL路径访问:/test/helloworld_addGlob.action

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值