nothingtodisplay
nothingtodisplay

Reputation: 31

Struts2 href trigger an action with parameter

I have a link in JSP like this

<a href="<s:url action="aUrlAction" />">a variable</a>

The struts2 action code is

public SomeAction extends ActionSupport{
    private String aVariable;
    // aVariable getters and setters
    public execute(){
        doSomeThing(aVariable);  
    }
}

Strtus2 mapping is

<action name="aUrlAction" class="***.SomeAction">
    <result>....</result>
</action>

How can I pass in aVariable from clicking <a> tag. I want pass in the text between <a></a> to the action. Thanks.

Upvotes: 2

Views: 3693

Answers (1)

Manoj Sharma
Manoj Sharma

Reputation: 616

You can pass parameter like this :

<s:url var="test" action="aUrlAction">
  <s:param name="aVariable">value</s:param>
</s:url>
<a href="${test}">Test</a>

Upvotes: 2

Related Questions