hemlocker
hemlocker

Reputation: 1052

struts2 NoSuchMethodException when trying to access Action method from JSP

Struts2 newbie here. I've got a JSP file that has an anchor linking to an Action called "authenticate". When I click on the anchor, I get an error message: java.lang.NoSuchMethodException: mypackage.DisplayStuff.authenticate() java.lang.Class.getMethod(Unknown Source)

Here is my struts.xml

<package name="default" extends="struts-default" namespace="/">
    <action name="display" method="authenticate"
        class="mypackage.DisplayStuff">
        <result name="error">Boo.jsp</result>
        <result name="success">Yay.jsp</result>

    </action>
</package>

And here is my action file:

package mypackage;

public class DisplayStuff {           
    public String authenticate() {
        return "success";
    }

}

And finally, in my JSP, I have this anchor:

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

The interesting part, is if I rename my method to the default "execute" I don't get this error. Shouldn't I be able to call any method in my DisplayStuff action?

Upvotes: 0

Views: 2438

Answers (2)

Roman C
Roman C

Reputation: 1

This should be

<a href="<s:url action="display" method="authenticate"/>">click here</a>

Upvotes: 0

Dave Newton
Dave Newton

Reputation: 160321

There are a few possibilities.

That the error message references a different package my first guess is that you haven't deployed the latest version of your code: struts.DisplayStuff.authenticate isn't how it's configured.

Second guess is an issue with a Struts 2 plugin (like "convention") mucking with your configuration.

Without more details, however, it's difficult to think much more about it.

Upvotes: 2

Related Questions