Struts 1 Lesson 1 Hello World with Maven 2


This page explains how you can get a basic struts hello world application up and running using Maven 2.

Lets start with the pom file and use it to regenerate our eclipse project.


Start by creating a project from a Maven archetype.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

Answer the rest of the questions like this▒?▒

Define value for groupId: : com.test
Define value for artifactId: : strutsTest
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  com.test: :

Hit enter for the rest of the defaults.

cd to the project’s folder
Next we create the src/main/java folder since this is not done for us using the archetype.

on unix you type: mkdir src/main/java

Next we generate the eclipse project (optional). The project is still not ready however this step makes editing the pom.xml file easier.

mvn eclipse:clean eclipse:eclipse

Import the Existing project (generated project) into eclipse.

Next steps are to typically modify the pom.xml file and insert the rest of the dependencies and regenerate the eclipse project by re-typing the above command and clicking refresh on the eclipse project.

Update your pom.xml file to look like this…

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <name>strutsTest Maven Webapp</name>

It all starts with the web.xml

In the above code you see spring included as a dependency. Lets leave it there for now since this example is used to build a project that uses spring with struts together.

Next we will modify the web.xml file


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





Next comes the struts-config.xml file. Both the web.xml and this file belong in the /WEB-INF folder.


<?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

                <action path="/HelloWorld"  type="com.test.HelloWorldAction">
                        <forward name="success" path="/helloWorld.jsp"></forward>

Next is the hello world struts action

package com.test;

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

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

public class HelloWorldAction extends org.apache.struts.action.Action {

    private final static String SUCCESS = "success";

    public ActionForward execute(ActionMapping mapping,ActionForm form,
           HttpServletRequest request,HttpServletResponse response) throws Exception {

        return mapping.findForward(SUCCESS);


Next we will create the JSP’s used to display the pages.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=<c:url value='/HelloWorld.do'/>"></HEAD>
Optional page text here.

Next is the Hello World page


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <title>XHTML 1.0 Strict Template</title>
  <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Language" content="en-us" />
Struts Hello World.

Test the application

Start up jetty and test your application

mvn jetty:run

navigate to http://localhost:8080/

You should see a Hello World message.

In the next section we will step thru the process of integrating spring with this simple struts application.

This site is a collaborative effort! The complete text and sourcecode for this is available on GitHub. Corrections and enhancements are welcome, please make the change and submit a pull request in the comment area below.

2 Responses to “Struts 1 Lesson 1 Hello World with Maven 2”

  1. 1 Ram
    December 8, 2012 at 2:27 am

    Very nice article. It perfectly worked for me. I was looking for skeleton project structure for struts 1.x and it helped me a lot. Could you please post more articles?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 77 other followers

September 2009
« Aug   Oct »

Blog Stats

  • 846,580 hits

%d bloggers like this: