ilovetolearn
ilovetolearn

Reputation: 2060

Struts 2 single jsp page to execute multiple different methods

I am migrating from struts 1 to struts 2 framework. Based on struts 1 framework parameter=method attribute, I am able to execute different methods using the same jsp page by adding a hidden field "method".

How do I achieve the same in struts 2?

My Action class:

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

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

My JSP page

<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>

Upvotes: 0

Views: 231

Answers (1)

PKey
PKey

Reputation: 3841

You could achieve that by changing the "action" url before submitting.

Check out Wildcard Method and Dynamic Method Invocation here

Though, the dynamic Method Invocation can be considered a Security Vulnerability

Upvotes: 1

Related Questions