Struts 2 Hello World Application using Eclipse

Learn the process of creating Struts 2 Hello World example in Eclipse IDE. This is step by step tutorial of developing Struts 2 Hello World application in Eclipse integrated development environment.

Creating Hello World application in Struts 2 version 2.3.15.1 using Eclipse

In this example we will learn how to make a Hello World Example in Struts
2 Framework. This is the first step for beginners in the field of developing
applications based on Struts 2 Framework. Here we have used Eclipse IDE for
creating the dynamic web application and added the Struts 2 libraries and code
into the project. We have used Tomcat 7 to run the example program.

This section will help you in writing your first Struts 2 applications using
Eclipse IDE. You can follow the step by step guide to develop your first Hello World
example in Struts 2, deploy on Tomcat 7 and test on browser.

Step 2: You should download and install latest version of
Eclipse IDE on your computer. Also configure the Tomcat 7 on Eclipse IDE so that
you can run the examples from the Eclipse IDE itself. If you don't know how to
configure Tomcat 7 with Eclipse IDE then just check the tutorial
Tomcat 7 in Eclipse Helios.

Step 3: Open the Eclipse IDE and create a dynamic web project as
shown below:

Name the project "Struts2HelloWorld" as shown below:

Eclipse IDE will create the project and it will display the project in the
Project explorer window as shown below:

Step 4: Create a new package "net.roseindia". Now
create a new Java file "HelloWorld.java" under the package "net.roseindia"
and add the following code:

The "HelloWorld.java" is our Action class which contains a
variable message whose value is picked up from a package.properties and
package_es.properties files. You will get the files from the source code of this
tutorial. You should copy and add the package.properties and
package_es.properties files from our download source code.

Step 5: Create index.jsp file in the "WebContent" directory
of the project. Add the following code:

Here in the above code <s:property value="message"/> tag is
used to print the value of message variable in the action class (HelloWorld
java).

Step 8: Finally add the required jar files from the
struts-2.3.15.1-all.zip zip file. You have to extract the
struts-2.3.15.1-all.zip file and copy the following jar files from the
lib directory into WebContent/WEB-INF/lib directory of
the Eclipse project:

asm-3.3.jar

asm-commons-3.3.jar

asm-tree-3.3.jar

commons-fileupload-1.3.jar

commons-io-2.0.1.jar

commons-lang3-3.1.jar

commons-logging-1.1.3.jar

freemarker-2.3.19.jar

javassist-3.11.0.GA.jar

log4j-1.2.17.jar

ognl-3.0.6.jar

struts2-core-2.3.15.1.jar

xwork-core-2.3.15.1.jar

Step 9: We are done with the work and to test the project, right click on the
"Struts2HelloWorld" in the project explorer window and then
select Run as and then "Run on Server" as
shown below:

Select the "Tomcat v7.0 Server at localhost" and then click
Finish button. Eclipse will compile and then deploy the
application on Tomcat 7. After successful startup of the application Eclipse
will open the url
http://localhost:8080/Struts2HelloWorld/ in the browser as shown below:

To run the example click on the link "Test Struts 2 Hello World
example !!" . Browser should display the message as shown below: