How to trigger an action by clicking a link in Struts2

I use the framework experience. I have a simple problem.

I have a link on the page. I want the Struts2 action to be executed when the user clicks the link and wants to pass some parameters.

For instance:

link on page = My Link
Action I want to call = myTestAction (it is defined in struts.xml)
parameter I want to pass = typeA=false

How can i do this? I looked at the tag <s:url><s:param name="typeA" value="false"></s:url>. However, the parameter does not seem to pass. when I put the link on the link, I do not see any parameters.

+3
source share
4 answers

Try it.

<s:url id="url" action="myTestAction">
    <s:param name="typeA">false</s:param>
</s:url>
<s:a href="%{url}" >My Link</s:a>
+3
source

the action class must have setTypeA(String value) and getTypeA()declared in it for the code passed abovetypeA=false

I don’t know why they will do it ... or the rails ruined me.

0
source
        <s:url action="actionNameInStrutsXML" method="methodNameInYourClass" var="menuAdmin" />
          <s:a href="%{menuAdmin}">Menu</s:a>

, .

:

struts.enable.DynamicMethodInvocation "value =" true "

0
source

I think @vinayak's answer is perfect if you want to send more than one parameter escapeAmp=false

0
source

Source: https://habr.com/ru/post/1731790/


All Articles