@ Resultpath of struts2

Source: Internet
Author: User

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.