ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Computer Programming Tutorials

How to create dynamic web project using struts2 and Maven in Eclipse IDE or Spring Tool Suite IDE?

Updated on November 24, 2013

In this example, a simple hello program will be implemented using Struts 2. We will use Maven as a build tool in our project.

Full project structure

The full structure of this project looks like the following:

Required tools/ libraries:

For this tutorial, we will use the following tools or libraries:

  1. JDK 1.5 or latest version
  2. Eclipse 4.3.0 or above
  3. Maven 4.0.0 or above
  4. M2Eclipse Plugin

Sometimes, you may need to figure out the version of Eclipse or Maven. You may watch the following videos to confirm that.

How to find Eclipse version

How to find Maven version?

Steps to create dynamic web project using struts2 and Maven in Eclipse IDE or Spring Tool Suite IDE:

Step 1: Creating a new Maven project in Eclipse

Create a new Maven project from File > New > Project.. and select Maven Project into your Eclipse by specifying the following Archetype parameters:

  1. GroupId: com.hubpages.plusminus
  2. AartifactId: MavenDemo
  3. Version: 0.0.1-SNAPSHOT
  4. Package: com.hubpages.plusminus.MavenDemo

Step 2: Add Struts2 dependencies

We will use Maven to download the entire Struts2 dependencies. To do this, just add struts2-core in pom.xml. Add the Struts 2 dependencies by the following information:

  1. Group Id: org.apache.struts
  2. Artificat Id:struts2-core
  3. Version:

Full code of pom.xml file [pom.xml]

<project xmlns="" xmlns:xsi=""
	<name>MavenDemo Maven Webapp</name>



Step 3: Configuring the web.xml

Create a new xml file under src/main/webapp/WEB-INF folder and named it as web.xml. web.xml configuration file is a J2EE configuration file. This file determines how elements of the HTTP request are processed by the servlet container. To make Struts2 working, you must need to configure this file.

Full code of web.xml [web.xml]

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Archetype Created Web Application</display-name>




Step 4: Create an action class

Actions are the core of the Struts2 framework. Each URL is mapped to a particular action. And in action class, you need to implement those using your own business logic. For this tutorial, we create an action class named as MavenDemo.

Full code of action class []

package com.hubpages.plusminus;

import com.opensymphony.xwork2.ActionSupport;

public class MavenDemo extends ActionSupport{

	private static final long serialVersionUID = 1L;

	public String message = "Hello PlusMinus....";
	public String getMessage() {
		return message;

	public void setMessage(String message) {
		this.message = message;

	public String displayMessage(){
		return SUCCESS;
	public String executeAll(){
		return SUCCESS;
	public static void main (String args[]){
		MavenDemo md = new MavenDemo();

Step 5: Creating a view page using JSP

It's time to create a view page. This jsp page will just displays the message of our action class.

Full code of JSP page [index.jsp]

<%@ taglib prefix="s" uri="/struts-tags" %>

<!-- <h2>Hello World!</h2> -->
<h1> Welcome to PlusMinus's home page </h1>
<br />

<s:property value="message"/>

<font style="font-family:arial;color:blue;font-size:20px;">Plus</font>
<font style="font-family:arial;color:red;font-size:20px;">Minus</font>

	<font style="color:green;;">____________________________________________</font> <br />
	<font style="color:green;margin-left:200px;">Copyright © PlusMinus</font>


Step 6: Configuring the struts.xml [struts.xml]

Each project of Structs2 has a configuration file which is defined in struts.xml file. Create a struts.xml file and configure the file. Configuring the file means, to create all links all action and result of your Java project. Remember, the configuration name must be struts.xml otherwise it will not work.

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

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

	<package name="basicStruts" extends="struts-default">
		<action name="hello" class="com.hubpages.plusminus.MavenDemo">
			<result name="success">/index.jsp</result>


Step 7: Running the struts 2 Maven project

Right-click on the Projct and select Run As option. "Run As" option will be expanded and you will find an option like Run on Server. Choose this option.


Choose the server where you want to run the application. For this tutorial, we choose Tomcat server and we select that. After selecting the server, click on Finish button.

Go to the browser and type http://localhost:8080/MavenDemo/hello into the browser address bar and hit Enter key. You will see the action class output in the browser.


    0 of 8192 characters used
    Post Comment

    • profile image

      mickle 3 years ago

      i like this post i will come back