Struts 2 Annotation: @ResultPath

By Arvind Rai, June 14, 2014
@ResultPath in struts 2 is used to change default location of results. @ResultPath annotation can be applied on class level as well as in package-info.java. It belongs to the package org.apache.struts2.convention.annotation. Default location of result is project root directory. We can change it as below
@ResultPath("/WEB-INF/user")
Now struts will look the above directory for results files. To understand the use of @ResultPath, I have taken two code snippet of action class.

Action Class Without @ResultPath

In this action class @ResultPath has not been used. So default location of result is project root directory and accordingly location attribute will be assigned for the file location.
@Namespace("/user")
@Action("/form")
@Result(name="success",location="/user/user.jsp")
public class UserAction extends ActionSupport{
	public String execute() {
	    return SUCCESS;
	}
} 

Action Class Using @ResultPath

In the below action class code snippet, @ResultPath is being used. Find the differences for location attribute.
@Namespace("/user")
@ResultPath(value="/")
@Action("/form")
@Result(name="success",location="user.jsp")
public class UserAction extends ActionSupport{
	public String execute() {
	    return SUCCESS;
	}
} 
POSTED BY
ARVIND RAI
ARVIND RAI







©2024 concretepage.com | Privacy Policy | Contact Us