Struts 2 单个 jsp 页面执行多个不同的方法

Struts 2 single jsp page to execute multiple different methods

我正在从 struts 1 迁移到 struts 2 框架。基于 struts 1 framework parameter=method 属性,我可以通过添加隐藏字段 "method".

使用相同的 jsp 页面执行不同的方法

如何在 struts 2 中实现同样的效果?

我的操作class:

public class MyAction extends ActionSupport {
    public String methodA() {
        return "a";
    }

    public String methodB() {
        return "b";
    }
}

我的 JSP 页面

<s:form action="MyAction">
    <s:select label="Method Name"
       name="method"
       headerKey="-1" headerValue="Select Method"
       list="#{'01':'A', '02':'B', [...]}"
       value="selectedMethod"
       required="true"
    />
    <s:submit type="button" name="submit" />
</s:form>

您可以通过在提交前更改 "action" url 来实现。

查看通配符方法动态方法调用 here

不过,动态方法调用可以被认为是一个Security Vulnerability