Struts 2 Hello World Example

 Download this Project

In this article, we will learn how to create a hello world example project using struts2.

1. Development Environment 

  1. Eclipse
  2. JDK 1.8
  3. Tomcat 8.5
  4. Maven

2. Create a Maven Web Project

Below is my dynamic web project struts2-helloworld structure in eclipse. In this example, we are using struts 2.1.8 version.

This project has a single action named “hello-world” and below is the source code for this project.


package com.simba.demo;

import com.opensymphony.xwork2.ActionSupport;

 * @author Simba
public class HelloWorldAction extends ActionSupport {

  private String name;
  public String sayHello() {
    return SUCCESS;

  public String getName() {
    return name;

  public void setName(String name) { = name;
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		Hello <s:property value="name" /> !
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


  <package name="helloWorld" namespace="/" extends="struts-default">
    <action name="hello-world" class="com.simba.demo.HelloWorld" method="sayHello">

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

<project xmlns="" xmlns:xsi=""

3. Testing

In your eclipse configure tomcat  and run your application by selecting Run on server.

When you open the URL: http://localhost:8080/struts2-helloworld/hello-world you will see the below output.


you can also add .action suffix  to your action name to access the output.