I'm following the Struts 2 Hello World Annotation Example tutorial by Mkyong:
@Namespace("/User")
@ResultPath(value="/")
@Action(value="/welcome",
results={@Result(name="success", location="pages/welcome_user.jsp")})
public class WelcomeUserAction extends ActionSupport {
public String execute(){
return SUCCESS;
}
}
Accessing the URL http://localhost:8080/project_name/User/welcome works fine.
Now I'm trying to move the @Action (and hence @Result) annotation from class level to method level:
@Namespace("/User")
@ResultPath(value="/")
public class WelcomeUserAction extends ActionSupport {
@Action(value="/welcome",
results={@Result(name="success", location="pages/welcome_user.jsp")})
public String execute(){
return SUCCESS;
}
}
But after doing this, I get the 404 error:
/project_name/pages/welcome_user.jspis not found.
My JSPs are under
/WebContent/User/pages
Why is this happening ?
Since Struts2 will look for your JSPs in
Instead of doing
you could move your JSPs from
to
and then using
At this point, both the following configurations should work:
With
@Actionat class level:With
@Actionat method level:I don't know why Mkyong's example works only with annotations at class level, and I'm waiting for someone more expert to fullfil our curiosity; meanwhile, this should be what you need.