Tutorial: Creating Struts application in Eclipse

[ad name=”AD_INBETWEEN_POST”] Note: If you looking for tutorial “Create Struts2 Application in EclipseClick here.
In this tutorial we will create a hello world Struts application in Eclipse editor.
We will implement a web application using Struts framework which will have a login screen. Once the user is authenticated, (s)he will be redirected to a welcome page.

Let us start with our first struts based web application.

First let us see what are the tools required to create our hello world Struts application.

  1. JDK 1.5 above (download)
  2. Tomcat 5.x above or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (download)
  3. Eclipse 3.2.x above (download)
  4. Apache Struts JAR files:(download). Following are the list of JAR files required for this application.
    • struts.jar
    • common-logging.jar
    • common-beanutils.jar
    • common-collections.jar
    • common-digester.jar

Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.

After selecting Dynamic Web Project, press Next.

Write the name of the project. For example StrutsHelloWorld. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.

Once the project is created, you can see its structure in Project Explorer.

Now copy all the required JAR files in WebContent -> WEB-INF -> lib folder. Create this folder if it does not exists.

Next step is to create a servlet entry in web.xml which points to org.apache.struts.action.ActionServlet class of struts framework. Open web.xml file which is there under WEB-INF folder and copy paste following code.


Here we have mapped url *.do with the ActionServlet, hence all the requests from *.do url will be routed to ActionServlet; which will handle the flow of Struts after that.

We will create package strutcures for your project source. Here we will create two packages, one for Action classes (net.viralpatel.struts.helloworld.action) and other for Form  beans(net.viralpatel.struts.helloworld.action).

Also create a class LoginForm in net.viralpatel.struts.helloworld.action with following content.

package net.viralpatel.struts.helloworld.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm {

	private String userName;
	private String password;
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors actionErrors = new ActionErrors();
		if(userName == null || userName.trim().equals("")) {
			actionErrors.add("userName", new ActionMessage("error.username"));
		try {
		if(password == null || password.trim().equals("")) {
			actionErrors.add("password", new ActionMessage("error.password"));
		}catch(Exception e) {
		return actionErrors ;
	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;

LoginForm is a bean class which extends ActionForm class of struts framework. This class will have the string properties like userName and password and their getter and setter methods. This class will act as a bean and will help in carrying values too and fro from JSP to Action class.
Let us create an Action class that will handle the request and will process the authentication. Create a class named LoginAction in net.viralpatel.struts.helloworld.action package. Copy paste following code in LoginAction class.

package net.viralpatel.struts.helloworld.action;

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

import net.viralpatel.struts.helloworld.form.LoginForm;

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 LoginAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String target = null;
		LoginForm loginForm = (LoginForm)form; 
				&& loginForm.getPassword().equals("admin123")) {
			target = "success";
			request.setAttribute("message", loginForm.getPassword());
		else {
			target = "failure";
		return mapping.findForward(target);

In action class, we have a method called execute() which will be called by struts framework when this action will gets called. The parameter passed to this method are ActionMapping, ActionForm, HttpServletRequest and HttpServletResponse. In execute() method we check if username equals admin and password is equal to admin123, user will be redirected to Welcome page. If username and password are not proper, then user will be redirected to login page again.

We will use the internationalization (i18n) support of struts to display text on our pages. Hence we will create a MessagesResources properties file which will contain all our text data. Create a folder resource under src (Right click on src and select New -> Source Folder). Now create a text file called MessageResource.properties under resources folder.

Copy the following content in your Upadate:struts-config.xml MessageResource.properties file.

label.username = Login Detail
label.password = Password
label.welcome = Welcome

error.username =Username is not entered.

Create two JSP files, index.jsp and welcome.jsp with the following content in your WebContent folder.


<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>

		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Login page | Hello World Struts application in Eclipse</title>
	<html:form action="login">
		 <bean:message key="label.username" />
		 <html:text property="userName"></html:text>
		 <html:errors property="userName" />
		 <bean:message key="label.password"/>
		<html:password property="password"></html:password>
		 <html:errors property="password"/>


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Welcome page | Hello World Struts application in Eclipse</title>
		String message = (String)request.getAttribute("message");
		<h1>Welcome <%= message %></h1>

Now create a file called struts-config.xml in WEB-INF folder. Also note that in web.xml file we have passed an argument with name config to ActionServlet class with value /WEB-INF/struts-config.xml.

Following will be the content of struts-config.xml file:

<?xml version="1.0" encoding="ISO-8859-1" ?>

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

		<form-bean name="LoginForm"
			type="net.viralpatel.struts.helloworld.form.LoginForm" />


		<action path="/login" name="LoginForm" validate="true" input="/index.jsp" 
			<forward name="success" path="/welcome.jsp" />
			<forward name="failure" path="/index.jsp" />

	<message-resources parameter="resource.MessageResource"></message-resources>

And, that’s it :) .. We are done with our application and now its turn to run it. I hope you have already configured Tomcat in eclipse. If not then:

Open Server view from Windows -> Show View -> Server. Right click in this view and select New -> Server and add your server details.
To run the project, right click on Project name from Project Explorer and select Run as -> Run on Server (Shortcut: Alt+Shift+X, R)

Login Page

Welcome Page

Related: Create Struts 2 Application in Eclipse

Get our Articles via Email. Enter your email address.

You may also like...


  1. Sabar says:

    Hi Viral,

    Thanks for the tutorial. I am getting the below error:

    org.apache.jasper.JasperException: The absolute uri: http://jakarta.apache.org/struts/tags-html cannot be resolved in either web.xml or the jar files deployed with this application

    Please help me..

    • Viral Patel says:

      @Sabar: Please check the Struts jar file version you using in your project. It seems the taglib is not correct and giving error. Check the jar version.

  2. naqi says:


    Can give the exact download link for the Apache Struts JAR files:

    As the problem i face, whenever i click on the download hyperlink, so it redirects to a page where i am unable to understand that where i may find these mentioned JAR files. Can you please help me sort this problem. I am sorry as i am total new to using eclipse with struts..

  3. jaison joseph says:

    thank you

  4. hari says:

    Hi naqi,please find the jars in docjar.com

  5. sweety says:

    can you provide me an example where i can display the data in a drop down list from the database using struts framework,that is nothing but making drop down list configurable or dyanmic

  6. sveinne says:

    Hi Im trying to get the tutorial to work
    I follow it at all sems well until running the project through tomcat within Eclipse
    The the following error occurs:

    Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).

    The message appears wheither or not the Tomcat server is up or down outside of eclipse

  7. Eric says:

    thx a lot for this application, it run correctly in my machine.congratulations

  8. Arun N says:

    type Exception report


    description The server encountered an internal error () that prevented it from fulfilling this request.


    javax.servlet.ServletException: Missing message for key “label.username”

    root cause

    javax.servlet.jsp.JspException: Missing message for key “label.username”

    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

    • Viral Patel says:

      @Arun – The messageresource.properties file seems to be not loaded. Check if the “resource” folder is added as source folder. Right click on project -> Properties -> Java Build Path -> Under source folder and path, Add Folder..

  9. Arun N says:

    I used the jdk 1.5 and tomcat 5, Please guide me over this issue.

    thanks in advance

  10. John says:

    First off, thank you for making this tutorial.

    Second I am having an error once I run the project. I know I copied all the code exactly into eclipse and have all the folders set up the same way but I don’t understand why I’m getting an error.

    The error is below, has anyone gotten this error or know how to fix it?

    javax.servlet.jsp.JspException: Missing message for key “label.username”
    at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:297)
    at org.apache.jsp.index_jsp._jspx_meth_bean_005fmessage_005f0(index_jsp.java:167)
    at org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0(index_jsp.java:111)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:80)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

    • Vidi says:

      Actually you can also check if you have clearly wiiten the param name for loading your ressource file MessageResource in your struts config or could be your resource file name does not match the one in your struts config..:-)

    • mansoor shaik says:

      place MessageResources.properties file in “javaresources/src/resource/MessageResources.properties.

      if u put messageresouces. properties file outside src folder it will not read.

  11. MAnoj says:

    Good example.. I am able to run it successfully. Except I have to go in deep with more concentration in understanding the communication between various classes and config files.


  12. Arun says:

    I also received the same error “javax.servlet.jsp.JspException: Missing message for key “label.username””.
    Adding the resource folder in to the java build path didnt resolve the error.

    This is how I resolved the error.
    I moved the ‘MessageResource.properties’ into src\resource folder and everything is working fine.

    Thanks for making this tutorial

    • Deepika says:

      @Arun: How did you move resource folder under src folder..i’m not able to do it..plz help

    • Raj says:

      Please make sure that the “resource” folder is created under “src” directory. Or you can create some other directory structure like package(net.struts.helloworld.resource) under “src” and put the resource file in there. That will resolve the issue.

      Also, change <message-resources parameter=".MessageResources” /> in struts-config.xml

  13. PenetiPalowan says:

    This tutorial is awesome. . . For the first time i have successfully run a struts application.
    Many thanks ! ! ! !
    VIRAL U ROCKzzzzzzz

  14. Kaushik Pradeep says:

    I was finding it very hard to get a good tutorial on Struts.But this one is awesome.Initially I also got the label.username problem but as told by arun it eventually went when i moved resource folder inside src.Thank you Viral and Arun… :)

  15. Pradeep says:

    Good tutorial!!!!

  16. star12 says:


    When I run it, im getting this exception. Can someone plz guide how to proceed. I have checked my struts.jar.. I see the classes Actionmappings and actionformbeans. Not sure why im still getting this.


    org.apache.jasper.JasperException: Cannot find ActionMappings or ActionFormBeans collection

    root cause

    javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
    root cause

    javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

    • jg001 says:

      Were u able to solve the exception u got. ‘Cannot find ActionMappings or ActionFormBeans collection’. I’ve also come across the same exception

  17. Deepika says:

    Hi Viral,

    I’m getting the same problem : (javax.servlet.ServletException: Missing message for key “label.username”).
    I tried moving resource folder under src folder…but unable to move it.
    Please help how can i move it under src folder.

    • Viral Patel says:

      Hi Deepika,
      To add resources folder as src folder, In Eclipse right click on project > Properties > Java Build Path > Source > Add Folder… and select your resources folder.

      • Chalapathi says:

        best tutorial…… simple way for understand purpose for all little java programmers

  18. pankaj says:

    Hi virul i m getting some errors
    org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 12

    javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

  19. suresh says:

    i want struts jar file free download site please tell me any one……………………………………
    help me please………….

  20. guts says:

    hi viral
    i have done exactly as you have mentioned in this tutorial
    but the problem i m facing is pasing exception of struts-config.xml file
    here is the full trace of errors:
    SEVERE: Parsing error processing resource path /WEB-INF/struts-config.xml
    java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)

    this occurs when i start the apache tomcat
    and then when I execute index.jsp, following errors occur

    org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

    Please help me in this issue
    Thanks an advance

  21. hitz says:

    hi, thanks for the code..but i m having some trouble getting it to work–>
    this is the error i got–> publishing to wasce2.1 failed

    Publishing failed
    java.lang.NoClassDefFoundError: Could not fully load class: org.apache.struts.taglib.html.JavascriptValidatorTag
    due to:org/apache/commons/validator/ValidatorResources
    in classLoader:
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    thsnks and regards

  22. Sunil says:

    Viral Patel
    Thanks for giving tutorilas,But
    1. check once again that in snap shot resource folde is not show under the src folder
    2. final screan shot also display wrong msg it show it will display Weclome admin but it will show welcome admin123 as we are setting password in request scope not user name

    Thanks once again

  23. Lokesh says:

    Excellent work Viral..Bt y only reply to girl

    • Viral Patel says:

      @Lokesh – Thanks Mate
      I ain’t gender biased :D

  24. Arun Shiva says:

    Hi Viral,
    Thanks very much for tutorial and i hope it gets even better with a video tutorial on this. Good work Viral..!!
    I am getting “Connection reset” problem in struts-config.xml for the use of

    please help me

  25. Pavithra says:

    Hi i m getting some errors
    org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 11
    javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

  26. Surya says:

    Thank you Based on you reference I successfully run the struts1 application. Thanks a lot.

  27. Hello All,

    While i was try to execute this I got following Exception, Please help me out, How can resolve this?

    javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class com.amit.form: {1}

  28. Raj says:

    Thanks a lot. This is a very good tutorial.

  29. Bilawal says:

    @Viral Getting this error

    HTTP Status 500 –


    type Exception report


    description The server encountered an internal error () that prevented it from fulfilling this request.


    org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

  30. Tushar says:

    Thanks lot after investing lot of time finally i execute struts program…Thanks lot again…

  31. Tushar says:

    Hi Viral,
    I changed username and password in loginForm still on welcome page its showing welcome admin123 and also taking only admin and admin123 as username and password if i did changes in loginForm….plz guide for same

  32. Joseph says:

    To resolve the missing message for key exception, copy the MessageResource properties file into the WEB-INF folder and in the struts-congig.xml file specify it as follows-

  33. sravan says:

    I got this error, plz show the proper solution,

    11 Jan, 2012 3:38:38 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: No getter method for property UserName of bean org.apache.struts.taglib.html.BEAN
    at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:1031)

    • Viral Patel says:

      @Sravan – Please check if you have used UserName instead of userName in JSP file.

  34. Kaushik says:

    How can i resolve this?
    org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
    root cause

    javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

    • Viral Patel says:

      @Kaushik – Please check if you have added action-mappings for LoginForm in your struts-config.xml?

      • Kaushik says:

        Yes Viral, its added…


        • redhat8 says:

          This is caused by wrong jar version. Please replace your jar with commons-digester-1.6.jar. That resolved my issue.

  35. sneha says:

    Hi Viral,
    Even i m facing the same problem javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection…I hv followed everything still I m unable to resolve… I am using RAD tool

    Thanks in advance

  36. krishna says:

    guys, please help me…

    I m not able to run any struts application, even the “struts2-blank” application which comes with Struts2.zip is also not running.
    I have installed and uninstalled tomcat for 5 time.

    Any help will be appreciated.

  37. shilkesha says:

    Hi Viral,

    I m getting below error:
    org.apache.jasper.JasperException: /index.jsp (line: 2, column: 74) File “/WEB-INF/struts-html.tld” not found

    in web.xml following declaration are:



    taglib declaration in jsp are:

    Please help to solve the error.

  38. srinu says:

    pls any body help me…………..i have some problem what is it that i am creating login page..in that login 3 types of users there..when click the login button it is identify the which type of user entered in this site..how it is recoginised..pls send me the code and explain it../……..

  39. Sekar says:

    Nice Tutorial. Was able to successfully run the application.

  40. RajeshR says:

    Modify execute in LoginAction Class for handling different targets for diff. users.
    Also add relevant targets(forward) in struts-config.xml

    Hope this helps.

  41. swethareddy.g says:

    hi viral the tutorial is really very helpful thanks for it.
    but i have a doubt

    “Now copy all the required JAR files in WebContent -> WEB-INF -> lib folder. Create this folder if it does not exists”
    from where we can get this jar files.

  42. jyo says:

    Hai viral…

    I am getting this error can u help me to resolve these…
    javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

  43. alsdias says:

    The tutorial is good.
    Better if a failure could redirect to a page that returns some feedback.
    At the first time you try a wrong password, for instance, it gets confusing because it seems that no action happens.
    So, I did the following:
    1. switched


    2. added the failed.jsp page which is a copy of index.jsp plus failure message.
    For example, follow the snippet:

    Failed – try again.
    … etc

  44. gopal says:

    Thanks Viral.

  45. Pavithra says:

    Hi every body…
    Thanks for the helpful tutorial. But i got a error as ” Missing message for key “label.username” ” . can any one help me to solve it.

    • pandiyan says:

      Have u created MessagesResources properties in resource folder under src.

  46. Phil says:

    FYI… I just went through this tutorial and found that I had to update the tab libraries in the index.jsp file to the following:

    Thanks for the great article!

  47. Nilaxi says:

    Hi Viral,

    I want to learn Java and i just know the basic can you help me out to learn it completely

  48. Umesh Kumar says:

    Hi Virul,
    I am new in Java and got your website very useful for me. It gives me knowledge about first Struts program.

    Umesh Kumar

  49. MWS says:


    My have complete my setup and gone through the instructions which you have written here but unable to login through database validation. Can you please give some example.

    Thank in advance

  50. Sri says:

    I tried to run this example in eclipse. I got the following error. I’m new to struts. Can you pls guide what is going wrong.


    org.apache.jasper.JasperException: java.lang.NullPointerException: Module ‘null’ not found.

    root cause

    java.lang.NullPointerException: Module ‘null’ not found.

Leave a Reply

Your email address will not be published. Required fields are marked *