Hello World with Struts 1 in Eclipse IDE

In the previous post we saw the architecture of Struts 1. Now this post will take you through the first illustrative program made up with the help of Struts 1 framework to display Hello World in browser in Eclipse IDE. I have used Eclipse 3.7 and Tomcat 6 for developing the example set.

First of all click on New Project and the Dynamic Web Project.

Select Dynamic Web Project

Select Dynamic Web Project

Then Eclipse will ask you for name of the project. Enter the name of the project and click on finish.

Provide Project Name

Provide Project Name

This will create a web project in Eclipse which can be exported as war file and run on Tomcat 6 server.

The next step will be to add struts jar files. The following jar files should be added to the project for successful deployment of struts project :

  • antlr-2.7.2.jar
  • commons-beanutils-1.8.0.jar
  • commons-chain-1.2.jar
  • commons-digester-1.8.jar
  • commons-logging-1.0.4.jar
  • commons-validator-1.3.1.jar
  • oro-2.0.8.jar
  • struts-core-1.3.10.jar
  • struts-taglib-1.3.10.jar

These jar files can be downloaded from the link with the Struts 1.3 distribution.You can put these jar files to the directory under WebContent -> WEB-INF -> lib.

Now we have to configure ActionServlet of struts with web.xml. The following xml shows how to configure struts in web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">




We have registered ActionServlet class in web.xml for the url “*.do” , that means every url that ends with “.do” will be taken care by Struts. We have to also specify location of struts-config.xml as init-param with name “config“. Struts reads the file struts-config.xml about the configuration that we provide to the struts such as FormBeans, Actions, Plugins , Global Forwards etc.

After that we have to create a form bean that will be sub class of ActionForm class which will bw act as model in out application and will contain application state. Following is our form bean named “HelloWorldForm”.

package com.raistudies.forms;

import org.apache.struts.action.ActionForm;

public class HelloWorldForm extends ActionForm {

    private static final long serialVersionUID = 7352021000623040587L;

    private String hello = null;

    public HelloWorldForm() {
        hello = "Hello World";

    public String getHello() {
        return hello;

    public void setHello(String hello) {
        this.hello = hello;

This form bean contains single property named as “hello” which stores “Hello World” as default value. Our next step will be to create a controller helper class that will help to handle a particulate url pattern. The url pattern will be specified and associated with our controller helper class in the file struts-config.xml. Our controller helper class must be a subclass of “Action” class provided in struts jar. We the url will be requested to the server, struts will run “execute” method of the associated with the url and returns the view in response. Following is our controller helper class named as “HelloWorldAction” :

package com.raistudies.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HelloWorldAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
        return mapping.findForward("hello");


The ActionForm object will contain instance of our form bean i.e. HelloWorldForm. The execute method returns string “hello” as the ActionForward. All the configuration regarding the action will be made as in the file struts-config.xml mentioned bellow.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

    <!-- ========== Form Bean Definitions ================================== -->
        <form-bean name="HelloForm" type="com.raistudies.forms.HelloWorldForm"/>
    <!-- ========== Action Mapping Definitions ============================= -->
        <action name="HelloForm" path="/HelloWorld" type="com.raistudies.actions.HelloWorldAction" scope="request" >
            <forward name="hello" path="/HelloWorld.jsp"/>

As you can see, we have registered our form bean com.raistudies.forms.HelloWorldForm with name “HelloForm” and put our controller helper class com.raistudies.actions.HelloWorldAction with the following attributes :

  1. name = “HelloForm” : It specifies the name of the form bean to be use as Model and in this case it is com.raistudies.forms.HelloWorldForm.
  2. path=”/HelloWorld” : It indicate the url associated to the controller helper class. In this case whene we will hit the url /HelloWorld.do , action will be invoked.
  3. scope=”request” : It indicates that the model or the form bean HelloForm will be stored in HttpServletRequest instance. the other option can be “session”.

<forward name=”hello” path=”/HelloWorld.jsp” redirect=”true”/> indicated a view as HelloWorld.jsp that is named as “hello”. That means if the execute method returns ActionForward with value “hello”, server will send HelloWorld.jsp as response.

So the directory structure of the project will be like bellow figure :

Directory Structure

Directory Structure

When we will run the project in Tomcat 6 bellow output window will be the output :

OutputYou can download source code or war file from bellow links.

Source : Download

WAR File : Download

Related Posts:

Leave a comment ?


  1. Excellent dude…
    nice detail description …
    Good Go Ahead.. 😀

  2. dude where is index.jsp and HelloWorld.jsp

Leave a Comment Cancel reply

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Trackbacks and Pingbacks:

  • URL - Trackback on 2012/12/24/ 06:20