From: http://blog.csdn.net/yandufeng/article/details/8105495
Here I want to add: To understand annotation, the best way is to look at the source code, Struts Convention source code in the struts2-convention-plugin-2.1.6.jar
In struts2, @ resultpath annotation is used to control the struts2 where to find the storage JSP page, by default it finds the JSP page in the WEB-INF/content/directory
@ Resultpath example
An action class that sets/user as namespace to jump to the/pages/login. jsp page
1 @Namespace("/User")2 @Result(name="success",location="pages/login.jsp")3 public class LoginAction extends ActionSupport{
4 }
Access it
http://localhost:8080/Struts2Example/User/login.action
Struts 2 will find the "login. jsp" from the default location
/Struts2Example/WEB-INF/content/User/pages/login.jsp
Custom resultpath
1 @Namespace("/User")2 @ResultPath(value="/")3 @Result(name="success",location="pages/login.jsp")4 public class LoginAction extends ActionSupport{
5 }
http://localhost:8080/Struts2Example/User/login.action
/Struts2Example/pages/login.jsp
Global @ resultpath
@ Resultpath is only applicable to the class level. To render it, you can configure it in struts. xml
Struts. xml
1 <?xml version="1.0" encoding="UTF-8" ?>2 <!DOCTYPE struts PUBLIC3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"4 "http://struts.apache.org/dtds/struts-2.0.dtd">5 <struts>6 <constant name="struts.convention.result.path" value="/"/>7 </struts>