Dhora
Dhora

Reputation: 33

Can I call a Struts2 action on click of a html link in html page

I want a Struts2 action to be performed on click of a html link in a html page. My first question is whether is it possible to perform a Struts2 action in a html page(not JSP)? If yes, take a look at my code below:

home.html

href="home.action"


struts.xml

action name="home" class="com.struts.action.HomeAction"

      result name="Success">loginJSP.jsp

*****web.xml***** I did filter mapping such that everything goes to Struts2

Upvotes: 1

Views: 16906

Answers (2)

Accollativo
Accollativo

Reputation: 1559

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

In this way you can call the method that you prefer.

Remember to put in your struts config this:

struts.enable.DynamicMethodInvocation" value="true"

Upvotes: 0

sjt
sjt

Reputation: 1587

Have you tried this?

<a href="<s:url action="actionName"/>">click here</a>

Or this?

<a href="/abc/actionname.action">Click here</a><br />

Also see: http://struts.apache.org/2.x/docs/url.html

Just curious to know, why can't you use JSP?

Upvotes: 7

Related Questions