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.
[ad#blogs_content_inbetween]

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.

<servlet>
		<servlet-name>action</servlet-name>
		<servlet-class>
			org.apache.struts.action.ActionServlet
		</servlet-class>
		<init-param>
			<param-name>config</param-name>
			<param-value>/WEB-INF/struts-config.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>action</servlet-name>
	<url-pattern>*.do</url-pattern>
</servlet-mapping>

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.
[ad#blogs_content_inbetween]

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) {
			e.printStackTrace();
		}
		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; 
		    
		if(loginForm.getUserName().equals("admin")
				&& 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.
[ad#blogs_content_inbetween]

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.

index.jsp

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

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

welcome.jsp

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

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"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

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


	<global-exceptions>
	</global-exceptions>
	<global-forwards></global-forwards>

	<action-mappings>
		<action path="/login" name="LoginForm" validate="true" input="/index.jsp" 
			type="net.viralpatel.struts.helloworld.action.LoginAction">
			<forward name="success" path="/welcome.jsp" />
			<forward name="failure" path="/index.jsp" />
		</action>
	</action-mappings>

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

[ad#blogs_content_inbetween]
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
[ad]

Get our Articles via Email. Enter your email address.

You may also like...

378 Comments

  1. 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
    regards
    S

  2. Eric says:

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

  3. Arun N says:

    type Exception report

    message

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

    exception

    javax.servlet.ServletException: Missing message for key “label.username”
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:91)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    root cause

    javax.servlet.jsp.JspException: Missing message for key “label.username”
    org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:235)
    org.apache.jsp.index_jsp._jspx_meth_bean_message_0(index_jsp.java:165)
    org.apache.jsp.index_jsp._jspx_meth_html_form_0(index_jsp.java:112)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:81)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    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..

  4. Arun N says:

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

    thanks in advance

  5. John says:

    Hey,
    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.

  6. MAnoj says:

    Hi,
    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.
    :)

    Thanks

  7. 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

  8. PenetiPalowan says:

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

  9. 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… :)

  10. Pradeep says:

    Good tutorial!!!!

  11. star12 says:

    Hi,

    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.

    exception

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

    root cause

    javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
    root cause

    javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:747)

    • 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

  12. 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

  13. 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
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)

  14. suresh says:

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

  15. 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
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)

    Please help me in this issue
    Thanks an advance

  16. 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
    hitz

  17. Sunil says:

    Hello
    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

  18. Lokesh says:

    Excellent work Viral..Bt y only reply to girl

    • Viral Patel says:

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

  19. 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

  20. 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
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)

  21. Surya says:

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

  22. Hello All,
    Greetings

    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}
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:96)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717

  23. Raj says:

    Thanks a lot. This is a very good tutorial.

  24. Bilawal says:

    @Viral Getting this error

    HTTP Status 500 –

    ——————————————————————————–

    type Exception report

    message

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

    exception

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

  25. Tushar says:

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

  26. 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

  27. 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-
    .

  28. 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.

  29. 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
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)

    • 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.

  30. 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

  31. 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.

  32. 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
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133)
    org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:166)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1425)
    org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    in web.xml following declaration are:

    http://jakarta.apache.org/struts/tags-html
    /WEB-INF/struts-html.tld

    http://jakarta.apache.org/struts/tags-bean
    /WEB-INF/struts-bean.tld

    taglib declaration in jsp are:

    Please help to solve the error.

  33. 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../……..

  34. Sekar says:

    Nice Tutorial. Was able to successfully run the application.

  35. RajeshR says:

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

    Hope this helps.

  36. 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.

  37. 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

  38. 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

    to

    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

  39. gopal says:

    Thanks Viral.

  40. 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.

  41. 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!

  42. Nilaxi says:

    Hi Viral,

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

  43. 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.

    Thanks
    Umesh Kumar

  44. MWS says:

    Hello,

    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
    MWS

  45. Sri says:

    Hi,
    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.

    exception

    org.apache.jasper.JasperException: java.lang.NullPointerException: Module ‘null’ not found.
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    java.lang.NullPointerException: Module ‘null’ not found.
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755)
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735)
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488)
    org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0(index_jsp.java:117)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:90)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

  46. krithika says:

    Hi

    Ur tutorial is really good and it works fine.
    I’m able to get the concepts better now.

    Thanks again for the detailed explanation

  47. Amit says:

    When I tried it after doing all above mentioned steps
    http://localhost:8080/StrutsHelloWorld/

    gives HTTP Status 404
    The requested resource is unavailable .

    Can somebody help me out :((

    • Mihir says:

      Amit try to stop the server(from task manager), and try to run it again. i also used to get same problem when i was developing an mvc architecture. At that time controller was not found. Even u can check your web.xml file there is possibility of error.

    • anuj says:

      Any luck with 404 error.
      I am also getting the same error. Did exactly as mentioned above.
      Please help.

      Thanks
      Anuj

  48. syed says:

    Getting error messages that org.apache.struts.helloworld can not be resolved type please tell me what to do

  49. Kevin says:

    Hi! I did exactly what you did and imported the necessary libraries into my Eclipse. However, I am still getting this error: org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: org.apache.struts.taglib.html.MessagesTei. Can somebody help me to see why this error exists?

    • Viral Patel says:

      Can you check if you have added all required JAR files in your project’s classpath.

  50. Sonali says:

    Hi! I did exactly what you did and imported the necessary libraries into my Eclipse. However, I am still getting this error:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 15

    12:
    13: Login
    14:
    15:
    16:
    17:
    18:

    Can You please send me the source /WAR file of this sample application. It seems like it is nt able to find the properties file.

    • nithin says:

      thats the mistake of your system configuration..just change it please..

Leave a Reply

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

You may 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>