Creating an Eclipse web project using Maven and Struts 1.x

In this article we are going to implement a web application using Struts framework which will have a login screen. Once the user is authenticated, user will be redirected to a welcome page.

Tools used :

  • Struts 1.3.10
  • Hibernate 4
  • Eclipse Indigo
  • JDK 6
  • Tomcat 6.0

Step 1 : Create Web Application Project using Maven Template

Create a Java web application project from “maven-archetype-webapp” template.

mvn archetype:generate -DgroupId=com.javawebtutor -DartifactId=StrutsWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

maven java project

Step 2 : Eclipse IDE integration

Convert this project to Eclipse web project with Maven command “mvn eclipse:eclipse -Dwtpversion=1.5".Open command prompt and navigate to generated "StrutsWebApp" project and issue following command.

mvn eclipse:eclipse -Dwtpversion=1.5

Step 3 : Import the Project into eclipse

Import the project into eclipse IDE. Directory structure of projects is given bellow.

maven java project

Step 4 : Update pom.xml file

Add the Struts dependencies in pom.xml. In Struts 1.x, you need the struts-core.jar for core module and struts-taglib.jar for tag library.

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




After updating the pom.xml again execute "mvn eclipse:eclipse -Dwtpversion=1.5". After executing this command Maven will download required libraries.

Step 5 : Create java directory :

Create a directory named java under main."/src/main".

Note:-If created java directory is not in class path of project,we need to add this directory to class path of your project.

Step 6 : Add java directory to classpath of the Project :

  • Right click on Project -> Build Path -> Configure build path.a new screen will open in that screen click on Source tab and then click on Add folder as shown bellow.

  • maven web project

  • Again one new screen will open and in that screen select the java checkbox and click on ok again OK as shown bellow.

maven web project

Now Java folder is in classpath of project.

Step 7 : Create FormBean class

Create a package com.jwt.struts.forms in java folder and create a class LoginForm in that package.Add bellow lines of code in this class.

package com.jwt.struts.forms;

import javax.servlet.http.HttpServletRequest;

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

public class LoginForm extends ActionForm {

	private static final long serialVersionUID = 1L;
	private String userName = null;
	private String password = null;

	public String getUserName() {
		return userName;

	public void setUserName(String userName) {
		this.userName = userName;

	public String getPassword() {
		return password;

	public void setPassword(String password) {
		this.password = password;

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.password = null;


Step 8 : Create Action Class

Create a package com.jwt.struts.action in java folder and create a class LoginAction in that package.Add bellow lines of code in this class.

package com.jwt.struts.action;

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;

import com.jwt.struts.forms.LoginForm;

public class LoginAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		LoginForm loginForm = (LoginForm) form;

		if (loginForm.getUserName() == null || loginForm.getPassword() == null
				|| !loginForm.getUserName().equalsIgnoreCase("Mukesh")
				|| !loginForm.getPassword().equals("kumar")) {
			return mapping.findForward("failure");
		} else
			return mapping.findForward("success");


Step 9 : Create jsp files

Create two jsp files login.jsp and success.jsp inside webapp directory of project.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib uri="" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Example</title>
	<html:form action="/login" focus="userName">
Username : <html:text property="userName" />
Password : <html:password property="password" />
		<html:submit value="login" />
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Page</title>
<h1>Hello JavaWebTutor</h1>

Step 10 : Create struts-config.xml

Create struts-config.xml under WEB-INF directory and add following code into this.

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

		<form-bean name="loginForm" type="com.jwt.struts.form.LoginForm" />
		<action name="loginForm" path="/login"
			type="com.jwt.struts.action.LoginAction" scope="request"
			<forward name="failure" path="/login.jsp" redirect="true" />
			<forward name="success" path="/success.jsp" redirect="true" />

Step 11 : update the web.xml file

Change the contents of WEB-INF/web.xml to

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	xmlns="" xmlns:web=""
	id="WebApp_ID" version="2.5">





Final Structure Of Project

Final structure of project is given bellow:

maven web project

Step 12 : Build the project

Open command prompt and navigate to "StrutsWebApp" project and issue mvn:package command.

mvn package

After executing above command "StrutsLoginEx.war" file will generate in target folder of the project.

Step 13 : Run it

Copy the generated "StrutsLoginEx.war" file from target folder to your tomcat webapp folder and start the server. After successful start of server open web browser and enter http://localhost:8080/StrutsLoginExample/login.jsp in URL bar we will see following output.

maven web project

Provide the value of username as mukesh and password as kumar you will see success.jsp page.

maven web project

You can download the source code of the example by clicking on the Download link below.

Source (Developed in Eclipse) : Download

comments powered by Disqus