Tutorial: Create Struts 2 Application in Eclipse
- By Viral Patel on December 23, 2009
- Featured, Struts 2, Tutorial

Welcome to the Part 2 of 7-part series where we will explore the world of Struts 2 Framework. In previous article we went through the basics of Struts2, its Architecture diagram, the request processing lifecycle and a brief comparison of Struts1 and Struts2. If you have not gone through the previous article, I highly recommend you to do that before starting hands-on today.
Struts 2 Tutorials
- Part 1: Introduction to Struts 2
- Part 2: Create Hello World Application in Struts 2
- Part 3: Struts 2 Validation Framework Tutorial with Example
- Part 4: Struts 2 Tiles Plugin Tutorial with Example
- Part 5: Struts 2 Interceptors Tutorial with Example
- Part 6: Struts 2 File Upload and Save Example
- Part 7: Struts 2 Ajax Tutorial with Example
Things We Need
Before we starts with our first Hello World Struts 2 Example, we will need few tools.
- JDK 1.5 above (download)
- Tomcat 5.x above or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (download)
- Eclipse 3.2.x above (download)
- Apache Struts2 JAR files:(download). Following are the list of JAR files required for this application.
- commons-logging-1.0.4.jar
- freemarker-2.3.8.jar
- ognl-2.6.11.jar
- struts2-core-2.0.12.jar
- xwork-2.0.6.jar
Note that depending on the current version of Struts2, the version number of above jar files may change.
Our Goal
Our goal is to create a basic Struts2 application with a Login page. User will enter login credential and if authenticated successfully she will be redirected to a Welcome page which will display message ” Howdy, <username>…!“. If user is not authenticated, she will be redirected back to the login page.

Getting Started
Let us start with our first Struts2 based application.
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.

Mapping Struts2 in WEB.xml
As discussed in the previous article (Introduction to Struts2), the entry point of Struts2 application will be the Filter define in deployment descriptor (web.xml). Hence we will define an entry of org.apache.struts2.dispatcher.FilterDispatcher class in web.xml.
Open web.xml file which is under WEB-INF folder and copy paste following code.
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Struts2 Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>Login.jsp</welcome-file> </welcome-file-list> </web-app>
The above code in web.xml will map Struts2 filter with url /*. The default url mapping for struts2 application will be /*.action. Also note that we have define Login.jsp as welcome file.
The Action Class
We will need an Action class that will authenticate our user and holds the value for username and password. For this we will create a package net.viralpatel.struts2 in the source folder. This package will contain the action file.

Create a class called LoginAction in net.viralpatel.struts2 package with following content.
package net.viralpatel.struts2;
public class LoginAction {
private String username;
private String password;
public String execute() {
if (this.username.equals("admin")
&& this.password.equals("admin123")) {
return "success";
} else {
return "error";
}
}
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;
}
}
Note that, above action class contains two fields, username and password which will hold the values from form and also contains an execute() method that will authenticate the user. In this simple example, we are checking if username is admin and password is admin123.
Also note that unlike Action class in Struts1, Struts2 action class is a simple POJO class with required attributes and method.
The execute() method returns a String value which will determine the result page. Also, in Struts2 the name of the method is not fixed. In this example we have define method execute(). You may want to define a method authenticate() instead.
The ResourceBundle
ResourceBundle is very useful Java entity that helps in putting the static content away from the source file. Most of the application define a resource bundle file such as ApplicationResources.properties file which contains static messages such as Username or Password and include this with the application.
ResourceBundle comes handy when we want to add Internationalization (I18N) support to an application.
We will define an ApplicationResources.properties file for our application. This property file should be present in WEB-INF/classes folders when the source is compiled. Thus we will create a source folder called resources and put the ApplicationResources.properties file in it.
To create a source folder, right click on your project in Project Explorer and select New -> Source Folder.

Specify folder name resources and press Finish.
Create a file ApplicationResources.properties under resources folder.

Copy following content in ApplicationResources.properties.
label.username= Username label.password= Password label.login= Login
The JSP
We will create two JSP files to render the output to user. Login.jsp will be the starting point of our application which will contain a simple login form with username and password. On successful authentication, user will be redirected to Welcome.jsp which will display a simple welcome message.
Create two JSP files Login.jsp and Welcome.jsp in WebContent folder of your project. Copy following content into it.
Login.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Struts 2 - Login Application | ViralPatel.net</title> </head> <body> <h2>Struts 2 - Login Application</h2> <s:actionerror /> <s:form action="login.action" method="post"> <s:textfield name="username" key="label.username" size="20" /> <s:password name="password" key="label.password" size="20" /> <s:submit method="execute" key="label.login" align="center" /> </s:form> </body> </html>
Welcome.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Welcome</title> </head> <body> <h2>Howdy, <s:property value="username" />...!</h2> </body> </html>
Note that we have used struts2 <s:> tag to render the textboxes and labels. Struts2 comes with a powerful built-in tag library to render UI elements more efficiently.
The struts.xml file
Struts2 reads the configuration and class definition from an xml file called struts.xml. This file is loaded from the classpath of the project. We will define struts.xml file in the resources folder. Create file struts.xml in resources folder.

Copy following content into struts.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
<action name="login"
class="net.viralpatel.struts2.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
</package>
</struts>
Note that in above configuration file, we have defined Login action of our application. Two result paths are mapped with LoginAction depending on the outcome of execute() method. If execute() method returns success, user will be redirected to Welcome.jsp else to Login.jsp.
Also note that a constant is specified with name struts.custom.i18n.resources. This constant specify the resource bundle file that we created in above steps. We just have to specify name of resource bundle file without extension (ApplicationResources without .properties).
Our LoginAction contains the method execute() which is the default method getting called by Sturts2. If the name of method is different, e.g. authenticate(); then we should specify the method name in <action> tag.
<action name="login" method="authenticate" class="net.viralpatel.struts2.LoginAction">
Almost Done
We are almost done with the application. You may want to run the application now and see the result yourself. I assume you have already configured Tomcat in eclipse. All you need to do:
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)
But there is one small problem. Our application runs perfectly fine at this point. But when user enters wrong credential, she is redirected to Login page. But no error message is displayed. User does not know what just happened. A good application always show proper error messages to user. So we must display an error message Invalid Username/Password. Please try again when user authentication is failed.
Final Touch
To add this functionality first we will add the error message in our ResourceBundle file.
Open ApplicationResources.properties and add an entry for error.login in it. The final ApplicationResources.properties will look like:
label.username= Username label.password= Password label.login= Login error.login= Invalid Username/Password. Please try again.
Also we need to add logic in LoginAction to add error message if user is not authenticated. But there is one problem. Our error message is specified in ApplicationResources.properties file. We must specify key error.login in LoginAction and the message should be displayed on JSP page.
For this we must implement com.opensymphony.xwork2.TextProvider interface which provides method getText(). This method returns String value from resource bundle file. We just have to pass the key value as argument to getText() method. The TextProvider interface defines several method that we must implement in order to get hold on getText() method. But we don’t want to spoil our code by adding all those methods which we do not intend to use. There is a good way of dealing with this problem.
Struts2 comes with a very useful class com.opensymphony.xwork2.ActionSupport. We just have to extend our LoginAction class with this class and directly use methods such as getText(), addActionErrors() etc. Thus we will extend the LoginAction class with ActionSupport class and add the logic for error reporting into it. The final code in LoginAction must look like:
package net.viralpatel.struts2;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private String username;
private String password;
public String execute() {
if (this.username.equals("admin")
&& this.password.equals("admin123")) {
return "success";
} else {
addActionError(getText("error.login"));
return "error";
}
}
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;
}
}
And that’s it. Our first Hello World Struts2 Application is now ready.
That’s All Folks
Execute the application in Eclipse and run it in your favorite browser.
Login page

Welcome page

Login page with error

Download Source Code
Click here to download Source Code without JAR files (9KB).
Moving On
Now that we have created our first webapp using Struts2 framework, we know how the request flows in Struts2. We also know the use of struts.xml and properties file. In this application we implemented a preliminary form of validation. In next part we will learn more about Validation Framework in Struts2 and implement it in our example.
Get our Articles via Email. Enter your email address.



Nice work dude …. keep it up… :) .. write some good post regarding PHP-MySQl also
Hi Gaurav, Thanks a lot for comment. I will sure try to write something on that too.
yes VIRal very good work nice approach followed……………..
still there is one problem viral when i am running the application it is showing http 404 error
please reply dear
@atif, have you specified welcome file in your web.xml? Please specify Login.jsp as welcome file in web.xml.
ya i have given the welcome file as login.jsp and the problem has been sorted out when i used tomcat 6.X
thanks for the reply
hi i implemented all d codes given above but when i start the server it gives
HTTP Status 404 –
——————————————————————————–
type Status report
message
description The requested resource () is not available.
@jawahar – Can you check if following code is present in your web.xml file.
<welcome-file-list> <welcome-file>Login.jsp</welcome-file> </welcome-file-list>ya its there viral and don know why its not coming……….
ya i checked its there but its not coming yar……
ya viral its there but its not coming………..
@jawahar – I will suggest you to check the source code properly. Download the source code of above tutorial and try to run it and see if everything is working well.
i recreated the project again it run successfully ………..i think some were went wrong………great work yarrrrrr………keep…….up the tempo………..
i have one doubt viral the following code in Login.jsp ………
y we put login.action …..y i m asking this ? means in struts.xml we mentioned name as “login” only thats y.
Hey Patel
I am also getting the resource not found error. I have made the project again & downloaded your code…what could be the other reason???
Thanks
hi patel
as i am new to struts give some more stuffs on that ur starter helps me a lot…….
thanks
Hi Viral
I downloaded the project & trying to run but I am having the same error which jawahar & ali were having. How can I remove that error & run the project successfully?
Thanks
Sadia
@Sadia – Check the server logs when the server starts. There must be some exception coming in there. Once reason I can think of is that some required jar file is missing or due to version difference there must be a ClassNotFound exception.
please add the commons-fileupload-1.2.1.jar file to the lib folder and try again.
Add commons-io and commons-fileupload jars
I’m getting a parsing error in web.xml :
Struts2 Application
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
Login.jsp
The exception is :
SEVERE: End event threw exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:928)
at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:193)
at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1138)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1072)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4377)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name struts
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2275)
… 35 more
Feb 11, 2010 4:07:40 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/StrutsWebApp/WEB-INF/web.xml
java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name struts
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2806)
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2832)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1072)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4377)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name struts
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2275)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:928)
at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:193)
at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1138)
… 27 more
It gives a Parse error in application web.xml file at jndi:/localhost/StrutsWebApp/WEB-INF/web.xml
java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name struts2
Thanks,
mizo
Hi
I just used your source file to recreate the project. But whatever I do I am getting some errors like,
SEVERE: Dispatcher initialization failed and
SEVERE: Exception starting filter struts2
I have used these jars from strtus 2.1.8.1 zip
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-2.0.7.jar
Can someone help me out from this.
Hi,
I am using eclipse 3.4, and struts2.1.8.1 verison , does difference in the versions of jar files cause some problems.
Looking forward to the replies.
Thanks in advance.
hi viral
can u please help me out
initially my struts2 project was running fine but now such an error comes up in eclipse:
Classpath entry E:/My_Folders/MyProj/eclipse/HelloWorld/WebContent/WEB-INF/lib/commons-logging-1.0.4.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.
what is the reason?
Hi viral,
Thanks for your application.
I am able to run the app. When i enter username and password.
in the loginaction class you have mention this.username and this.password.
actually those variables are null and I am geeting a nullpoint exception.
Actually i have worked on spring MVC.
there we use UIBean to get the variables from jsp page. But I dont know how you are able to get here.
Please explain ASAP.
regards,
Jagadish
Hi Viral,
does it matter what lib package of struts2 are you importing to this project ? I mean theoratically the latest version of struts2 – lib should work if I import. But as you mentioned I am getting error log saying – no class found filterdispatcher. I am sure this is due to version mismatch of jar files of struts2., But logically the latest version should be good right ?
Hi Viral,
I copied u r code and tried i got 404 exception. Then i tried by downloading the source code what u have given. Then also I got 404 exception.
This is the log what i got, can u please guess whats the problem i made.
Mar 12, 2010 11:32:48 AM org.apache.catalina.core.AprLifecycleListener lifecycle
Event
INFO: The Apache Portable Runtime which allows optimal performance in production
environments was not found on the java.library.path: D:\Tomcat 5.5\bin;.;C:\WIN
DOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Program Files\Common Files\Telec
a Shared;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Mi
crosoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools
\binn\
Mar 12, 2010 11:32:48 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 12, 2010 11:32:48 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 531 ms
Mar 12, 2010 11:32:48 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 12, 2010 11:32:48 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.12
Mar 12, 2010 11:32:48 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Mar 12, 2010 11:32:49 AM com.opensymphony.xwork2.util.logging.commons.CommonsLog
ger info
INFO: Parsing configuration file [struts-default.xml]
Mar 12, 2010 11:32:49 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 12, 2010 11:32:49 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/helloworld] startup failed due to previous errors
Mar 12, 2010 11:32:49 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 12, 2010 11:32:49 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 12, 2010 11:32:49 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15 config=null
Mar 12, 2010 11:32:49 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Mar 12, 2010 11:32:49 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1437 ms
Mar 12, 2010 11:33:22 AM com.opensymphony.xwork2.util.logging.commons.CommonsLog
ger info
INFO: Parsing configuration file [struts-default.xml]
Mar 12, 2010 11:33:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 12, 2010 11:33:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/helloworld] startup failed due to previous errors
Regards,
Vinayagam
opss.s… i can’t imagine how can you post a tutorial with too many errors
Good work Viral it is very helpful
Hi Viral , i could not able to view the 3 rd part of the struts example(Part 3: Struts 2 Validation Framework Tutorial with Example). please re upload
Hi Viral
Is your tutorial on Struts 1.*, Creating Struts application in Eclipse finished or does it missing some pages?
If yes, do you plan to finish it or should I look somewhere else, and in that case do you have any tips for me?
I’m interested in tutorials about Struts 1.2.9 with Eclipse
Cheers
Hi Viral,
Thanks for the tutorial, however I’m running into two issues.
1.) Eclipse is showing the error “Can not find the tab library descriptor for “/struts-tags”
The error appears in both Login.jsp and Welcome.jsp. My WEB-INF/lib contains the following jars; commons-collections-2.1.jar, commons-logging.1.0.4.jar, commons.logging-api-1.1.jar, freemarker-2.3.8.jar, spring-core-2.0.5.jar, and xwork-2.0.7.jar
2.) When I start the app, I receive the following stack trace:
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:249)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3800)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
I followed the tutorial step-by-step to ensure I was doing everything right, and then decided to give your code a try (in case I missed something) and that didn’t work either.
Thanks, and I really appreciate your efforts!
Chris
thanks dude !!! it worked !!!
you choice version struts struts2-core-2.1.6.jar,xwork-2.1.2.jar!
if error then you choice version!
tutorial is good!
hi Chris,
the jar files which you have added in the folder is not right.,
plz check:
1.Commons-logging-1.0.4.jar
2.freemarker-2.3.15.jar
3.ognl-2.7.3.jar
4.struts2-core-2.1.8.1.jar
5.xwork-core-2.1.6.jar
meen, thanks that worked!
Great Work !!
i’m getting http status 404 error
i’m using jboss v4.2
please help me to rectify the problem
its working now… thanks a lot for this good tutorial
Hi Viral,
I am getting the following error. I have checked that i have all the jar files as required in the application.
May 13, 2010 4:34:51 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\oracle\ora92\bin\;C:\Program Files\Oracle\jre\1.1.8\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\JDK\bin;D:\apache-maven-2.1.0\bin;C:\Program Files\Windows Imaging\
May 13, 2010 4:34:51 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 13, 2010 4:34:51 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 346 ms
May 13, 2010 4:34:51 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 13, 2010 4:34:51 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
May 13, 2010 4:34:51 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
May 13, 2010 4:34:51 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
May 13, 2010 4:34:51 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive StrutsHelloWorld.war
May 13, 2010 4:34:52 PM com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts-default.xml]
May 13, 2010 4:34:52 PM com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts-plugin.xml]
May 13, 2010 4:34:52 PM com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts.xml]
May 13, 2010 4:34:52 PM org.apache.struts2.config.Settings getLocale
WARNING: Settings: Could not parse struts.locale setting, substituting default VM locale
May 13, 2010 4:34:52 PM org.apache.struts2.config.BeanSelectionProvider register
INFO: Loading global messages from ApplicationResources
May 13, 2010 4:34:52 PM org.apache.struts2.spring.StrutsSpringObjectFactory
INFO: Initializing Struts-Spring integration…
May 13, 2010 4:34:52 PM org.apache.struts2.spring.StrutsSpringObjectFactory
SEVERE: ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app!
Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
You might need to add the following to web.xml:
org.springframework.web.context.ContextLoaderListener
May 13, 2010 4:34:52 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NullPointerException
at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:189)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:479)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:450)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:407)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:239)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:205)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
May 13, 2010 4:34:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
May 13, 2010 4:34:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsHelloWorld] startup failed due to previous errors
May 13, 2010 4:34:52 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [com.opensymphony.xwork2.ActionContext.ActionContextThreadLocal] (value [com.opensymphony.xwork2.ActionContext$ActionContextThreadLocal@6355dc]) and a value of type [com.opensymphony.xwork2.ActionContext] (value [com.opensymphony.xwork2.ActionContext@19a029e]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
May 13, 2010 4:34:52 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@126f827]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@16dfa45]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Pls help me in this regard
Thanks a lot. quick response will be highly appreciated.
The tutorial seems nice and simple. However, something is missing – I am getting 404 when running this application.
I use Eclipse. All files in the places described in this tutorial and all files contain what described in this tutorial. So Eclipse does not show any error in the code, or missing file. The server is working just fine for other appications (projects) that I had created in Eclipse, including some projects on Spring.
The error is about being unable to load some files from particular jar file:
Unable to load configuration….
blah-blah-blah…
…/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsHelloWorld/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml
Any advice?
This code works perfect unlike other tutorials where half of the instructions are missing. Thanks for an elaborate one. I too got an error on resource not found which was solved by adding commons-fileupload-1.2.1.jar and commons-io-1.3.2.jar to the WEB-INF/lib. Thanks Viral again.
Thanks to Viral Patel. I learned a lot about Struts. As Shrinivasan Neelamegam saidl, I also got an error “The requested resource (/StrutsHelloWorld) is not available.” But after adding commons-fileupload-1.2.1.jar and commons-io-1.3.2.jar to the WEB-INF –> lib folder I overcame that. Thanks a lot Viral. Cheers!!! :)
For people getting the 404 error. I was getting this same error and when I checked the tomcat logs I realized I had an exception on loading spring classes when I didn’t even use spring. If found out that this happened because I got lazy including ONLY the mentioned .jars and included them all on the /lib folder.
When the above procedure is done, the server will automatically search for files used to configure those jars and since they don’t exist because we haven’t defined them you will probably get a nullpointer exception. Bottom line, erase all jars you don’t need from WebContent/WEB-INF/lib/ and only leave the ones Viral mentioned (this solved the problem for me):
- commons-logging-1.0.4.jar
- freemarker-2.3.8.jar
- ognl-2.6.11.jar
- struts2-core-2.0.12.jar
- xwork-2.0.6.jar
Great tutorial, thenx!!
I had the same problem, you have to include:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
files to the WEB-INF/lib for application to run :)
good tut!
After clicking the login button, I am getting error as follows,
HTTP Status 500 –
——————————————————————————–
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NoSuchMethodException: net.viralpatel.struts2.LoginAction.authenticate()
java.lang.Class.getMethod(Unknown Source)
what is the mistake??
can anyone clarify me?
You cannot miss this line in struts.xml file. I made it work just by adding this line to struts.xml file.
HTTP Status 404 – /StrutsHelloWorld/
——————————————————————————–
type Status report
message /StrutsHelloWorld/
description The requested resource (/StrutsHelloWorld/) is not available.
——————————————————————————–
i am getting this when i run the above example. i dont know why. is there any problem in my tomcat?
plz help me
hello Viral
thanx a lot, ur tutorial solve my problem, i am new to learn java technology
stay blessed…
Thank You,
that was very nice……
although it shows some stupid error…
The requested resource () is not available.
but is shows error..
The requested resource () is not available.
i also tried with the downloaded source.
HTTP Status 404 – There is no Action mapped for namespace / and action name .
type Status report
message There is no Action mapped for namespace / and action name .
description The requested resource (There is no Action mapped for namespace / and action name .) is not available.
please let me know why this error is coming. I dint modify anything from above code.
/Login/LoginAssitancestep1.jsp
when i am deploy and run it in browser at that time when click on button, the button action name is “LoginAssi1.action” but in url it will show the folder name after Project name. like in this way
“http://localhost:15789/MF_SSOWEB/Login/LogAssi1.action”
how to remove “/Login” from the url………i want “http://localhost:15789/MF_SSOWEB/LogAssi1.action” in this only for in this what i can do………
if u know plz reply me……………..
my mail id is
“xxxx@gmail.com”
@vara: Check your struts.xml. In <package> tag does the namespace is “Login”? If so then change it to namespace=”/”. Hope this will work.
ya, i can try for it, but no use. in the url again “http://localhost:15789/MF_SSOWEB/Login/LogAssi1.action” came in this way. if remove “/Login” from the url it will came. now it will came, what is the problem in my code.
struts.xml:
/Registration/Registration.jsp
/Registration/Success.jsp
/Registration/Registration.jsp
/campagainplan/ProductPortal.jsp
/Login/Login.jsp
/Login/LoginAssitancestep1.jsp
/Login/LoginAssistancestep2.jsp
/Login/LoginAssitancestep1.jsp
/Login/LoginAssistancestep3.jsp
/Login/LoginAssistancestep2.jsp
/Login/LoginAssiEmail.jsp
/Login/LoginAssistancestep2ForgotPass.jsp
/Login/LoginAssiEmail.jsp
/Login/LoginAssiStep4.jsp
/Login/LoginAssistancestep2ForgotPass.jsp
/Login/Login.jsp
/Login/LoginAssistancestep3.jsp
/Login/ForgotPasswordComplete.jsp
/Login/LoginAssiStep4.jsp
/Login/Login.jsp
deploy?path=/home/varaprasads/NetBeansProjects/MF_SSOWEB/build/web&name=MF_SSOWEB&force=true failed on GlassFish v3 (2)
/home/varaprasads/NetBeansProjects/MF_SSOWEB/nbproject/build-impl.xml:695: The module has not been deployed.
i got the above error at the time of deploy………….what i can do for remove the error………….
hi Viral,
I am very new to Struts and Just have Idea of MVC. I was trying to develop the sturts application you have explained here. But unfortunately I m getting some exceptions here. Please look into it and help me.
Here is the Exception stack trace,
17 Jul, 2010 7:38:35 PM org.apache.catalina.core.AprLifecycleListener init
SEVERE: Dispatcher initialization failed
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest – bean – jar:file:/C:/Workspace/.metadata/.plugins/org.eclipse.wst.server.coreCaused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
17 Jul, 2010 7:38:37 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
17 Jul, 2010 7:38:37 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsHelloWorld] startup failed due to previous errors
The problem has been resolved now.
I have included commons-fileupload-1.2.1.jar in the WEB-INF/lib folder. After that it sarted working.
Thanks to Viral for a simple explanation.
Now I am facing new problem. Once I clicked the “Login” button in the Login.jsp page after entering the username and password, it does not redirect the page to either Welcome.jsp or Login.jsp. it does not show me the warning either, if at all I am entering the wrong username and password.
Here is the exception stack trace,
18 Jul, 2010 11:38:58 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:StrutsHelloWorld’ did not find a matching property.
18 Jul, 2010 11:38:58 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
18 Jul, 2010 11:38:58 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 801 ms
18 Jul, 2010 11:38:58 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
18 Jul, 2010 11:38:58 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.28
18 Jul, 2010 11:38:59 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-default.xml]
18 Jul, 2010 11:38:59 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Unable to locate configuration files of the name struts-plugin.xml, skipping
18 Jul, 2010 11:38:59 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-plugin.xml]
18 Jul, 2010 11:38:59 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts.xml]
18 Jul, 2010 11:38:59 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Loading global messages from ApplicationResources
18 Jul, 2010 11:38:59 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
18 Jul, 2010 11:38:59 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
18 Jul, 2010 11:38:59 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/26 config=null
18 Jul, 2010 11:38:59 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1608 ms
Can anyone please help me out in this case.. I cant sort it out this time.
awesome awesome…
Thanks to Viral and Sas…
M a lazy fellow, I added all the jar files.. and was dealing wd the errors as ppl abve
nice tutorial
Me Likes…
Hello Viral,
I am trying same tut in eclipse. I’ve included the .jar files you have said.
But m still getting the same problem as that of ‘Chris’ – “Can not find the tab library descriptor for “/struts-tags” in both Login.jsp and Welcome.jsp. I’ve included ‘servlet-2.3.jar’ extra.
Please help….
Thanks.
I followed this tutorial. when i click the submit button it doesn’t go to the welcome.jsp page.
it gives the following error message.
type Status report
message There is no Action mapped for namespace / and action name login.
my folder structure is same as above.
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
Sorry. I have made a mistake.
Error message is
Status report
message There is no Action mapped for namespace / and action name login.
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
in struts.xml file do this
remove method= authenticate. also in jsp files give space between ” and % you can run program