Struts2 Namespace Tutorial

1- @Namespace Annotation

@Namespace Is an annotation, it can use to annotate at package or class level. And it will have the effect for the Action class in the package or the Action class is annotated by @Namespace.
Normally, if your Action class is not annotated by @Namespace, and it is not belong to a package annotated by @Namespace, it is annotated by @Namespace(value = "/") by default.
// Configure an Action:

@Action(value = "hello", //
results = {
  // ...
public class HelloAction  extends ActionSupport

// ==================================
// Same as:

@Namespace(value ="/")
@Action(value = "hello", //
results = {
  // ...
public class HelloAction  extends ActionSupport
The illustration below shows how to access an 'Action' in a Namespace.
@Namespace annotated on the package:
package org.o7planning.struts2namespace.action;

2- Create Maven Project

In Eclipse create an Empty Maven Web App Project with name Struts2Namespace.

3- Configure Struts2, pom.xml & web.xml

Configure Struts2 in web.xml:
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi=""
     id="WebApp_ID" version="3.0">




Configure maven:
<project xmlns=""
  <name>Struts2Namespace Maven Webapp</name>


        <!-- Servlet Library -->
        <!-- -->

        <!-- -->

        <!-- -->



            <!-- Config: Maven Tomcat Plugin -->
            <!-- -->
                <!-- Config: contextPath and Port (Default: /Struts2Namespace : 8080) -->
                <!-- <configuration> <path>/</path> <port>8899</port> </configuration> -->



4- Struts2 Action & Jsp
package org.o7planning.struts2namespace.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;

@Namespace(value = "/web/info")
@Action(value = "aboutUs", //
        results = { //
                @Result(name = "success", location = "/WEB-INF/pages/aboutUs.jsp") //
        } //
public class AboutUsAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    public String execute() {

        return "success";

<!DOCTYPE html>
<meta charset="UTF-8">
<title>About Us</title>

 <h3>About o7planning</h3>
 <p>Address: Vietnam</p>
 <p>Contact: ... </p>


5- Running apps

  • Name: Run Struts2Namespace
  • Base directory: ${workspace_loc:/Struts2Namespace}
  • Goals: tomcat7:run