Struts 2 Hello World Example in Eclipse

Posted on : Tue, 15th Sep 15 06:50 am (Updated on : Tue, 15th Sep 15 06:50 am) UTC
Author : Code2care
100+ votes

In this program we will see how to create a "Hello World!" Example in Structs 2 in Eclipse IDE,

1. Right Click under Project Explorer and select New -> Dynamic Web Project

Caption : Creating Hello World! Project in Struts 2 using Eclipse IDE

2 . Project Name : HelloWorld, make sure you select the target runtime as the installed Apache Tomcat container version that you have installed on your system.

3 . Make sure you add the following jar files in WebContent -> WEB-INF -> lib folder :











4 . Create web.xml under WebContent -> WEB-INF folder,

File : web.xml Language : xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	xmlns="" xmlns:web=""
	id="WebApp_ID" version="2.5">

5. Create a package under Java Resource -> src folder, name it com.code2care.struct2

Create new Package


6. Create a java class file under com.code2care.struts2 called (this is our action class)

File : Language : Java
package com.code2care.struts2;

public class HelloWorldAction {

	private String name;

	public String execute() throws Exception {

		return "SUCCESS";


	public String getName() {
		return name;

	public void setName(String name) { = name;


7 . Create index.jsp under WEB-INF folder,

File : index.jsp Language : Jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib prefix="s" uri="/struts-tags"%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<title>Struts2 Hello World!</title>
   <h1>Struts2 : Hello world example in Eclipse </h1>
   <form action="helloform">
      <label for="name">Enter your name : </label>
           <input type="text" name="name"/><br/>

8 . Create greetingsPage.jsp folder under WEB-INF folder,

File : greetingsPage.jsp Language : Jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Struts 2 Hello world!</title>
  Hello <s:property value="name"/> !!

9 . Create classes folder under WebContent -> WEB-INF folder

classes folder

10 . Create struts.xml file under classes folder,

File : struts.xml Language : xml
<?xml version="1.0" encoding="UTF-8"?>
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	<constant name="struts.devMode" value="true" />
	<package name="HelloWorld" extends="struts-default">

		<action name="helloform" class="com.code2care.struts2.HelloWorldAction"
			<result name="SUCCESS">/greetingsPage.jsp</result>

Hello world Program Output :


Download :

  1. Hello world zip
  2. Hello world war

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +