Home  >  Struts 2

Struts 2 Annotations: @Namespace, @Results

By Arvind Rai, May 16, 2014
In this page, we will learn about @Namespace and @Results struts annotation. @Namespace hides the package structure from URL and @Results defines the response of action class. The usability of these annotation has been defined below in detail.

@Namespace Annotation in Struts 2

@Namespace is used at class level or package level. This helps to change the namespace for action class. While accessing or calling action class, it hides package structure. When namespace is applied at package level, all the action of that package gets that namespace as default.
public class UserAction extends ActionSupport{
	public String execute() {
	    return SUCCESS;
The above class can be accessed by @Namespace + @Action that is /user/form
will access UserAction class.
Package level @Namespace can be defined as below.
package com.concretepage.action; 

@Result and @Results Annotation in Struts 2

@Result and @Results define the response of action class. These annotations can be applied at class level as well method level. @Result defines one response and @Results defines more than one response.
	  @Result(name="success", location="/user/user.jsp"),
	  @Result(name="failure", location="/user/error.jsp"),
public class UserAction extends ActionSupport{
	public String one() {
	    return "success";
	public String two() {
	    return "failure";
will respond to user.jsp and
will respond to error.jsp

©2020 concretepage.com | Privacy Policy | Contact Us