Struts 2 Hello World Example in Eclipse

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

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
<?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

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

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
<%@ 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
<%@ 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

10. Create struts.xml file under classes folder,

File: struts.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>

Recent Posts:
Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on and support us pay our bills.

Cod2ecare - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.