Share on Google+Share on Google+

Deploying Struts and testing struts 2 hello world application

I am assuming that you have already installed ant build tool on your machine

Deploying Struts and testing struts 2 hello world application


I am assuming that you have already installed ant build tool on your machine. Since we are using the ant built tool to build the application. To build the application open command prompt and go to "struts2helloworld\WEB-INF\src" directory of the web application and issue the "ant" command. The ant build tool will compile the java file and create jar file "struts2tutorial.jar" into the lib directory of your web application. Here is the output of ant build tool:

Buildfile: build.xml

[delete] Deleting directory C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\classes
[mkdir] Created dir: C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\classes



[javac] Compiling 1 source file to C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\src\classes
[jar] Building jar: C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\lib\struts2tutorial.jar



Total time: 19 seconds

Testing Struts 2 Hello World Application

In the above section we have compiled our application and now finally we will test our application. To test the application start the tomcat server and type http://localhost:8080/struts2HelloWorldApplication/ and then select "Run Struts 2 Hello World Application" from the list. 

Here is the output of struts 2 Hello World Application:

When run this application you get:


After clicking on the "Run Struts 2 Hello World Application" Then you get the message "Struts 2 Hello World Application" on the screen.

How application works?

Here is the brief description on how Struts 2 Hello World Application works:

Your browser sends a request to the web server for the URL http://localhost:8080/struts2HelloWorldApplication/roseindia/HelloWorld.action 

  1. When you click on the "Run Struts 2 Hello World Application" link, the browser sends a request for the url http://localhost:8080/struts2HelloWorldApplication/roseindia/HelloWorld.action. The container requests for the resource "HelloWorld.action". By default web.xml file of struts blank application is configured to route all the request for *.action through  org.apache.struts2.dispatcher.FilterDispatcher. 

    Here is the configuration from web.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" version="2.4" xmlns="

      <display-name>Struts Blank</display-name>





  2. Then the framework looks for the mapping for the action "HelloWorld" and then framework instantiates the appropriate class and calls the execute method. In this case action class is Struts2HelloWorld. Here is the configuration file from struts.xml which defines the action mapping:
    <action name="HelloWorld" class="net.roseindia.Struts2HelloWorld">

  3. Then the execute method sets the message and returns SUCCESS. 
    public String execute() throws Exception {
      return SUCCESS;

    Then framework determines which page is to be loaded if SUCCESS is returned. In our case framework tells the container to load HelloWorld.jsp and render the output.

    In the struts 2 framework Actions are used to process the form and user request. The execute method of the action returns SUCCESS, ERROR, or INPUT value. Then based on these values framework tells the container to load and render the appropriate result.
  4. Container process the HelloWorld.jsp and generates the output.
  5. Then the output in the HTML format is sent to the browser.

Download "Hello World" Application



Posted on: June 10, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Deploying Struts and testing struts 2 hello world application   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image