Recently I’ve started learning the Struts 2 framework. Though I’ve been using Struts 1.3 for quite some time, understanding Struts 2 was little tricky as the ‘Hello World sample application’ provided by Struts 2 site is little confusing. So, I was searching for a simple ‘Hello world example for Struts 2′ and after going through many different sites, finally I was able to run my first Struts 2 application. Here are the steps that I did to start with Struts 2. I am using Eclipse IDE and all the steps explained below are in referring to Eclispe 3 IDE.
Struts 2 Hello World Application – Getting started with Struts 2
- Create New : Project : Dynamic Web Project and give a name to your project and the location to save your project. For this example, I gave HelloWorld as my project name.
- Second step will be including JAR files required by Struts 2 framework to our project’s WEB-INF/lib folder. You can either download below JARs separately or simple copy them from the lib folder of struts2-blank-application provided by Struts 2 website. Note that the version numbers in the JAR files are the latest ones when this article written. You may use the latest JARs if they are available.
- commons-logging-1.0.4.jar
- freemarker-2.3.8.jar
- ognl-2.6.11.jar
- struts2-core-2.0.11.jar
- xwork-2.0.4.jar
- Next step will be configuring struts 2 filter in web.xml file. Have a look at the below sample configuration.
<?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>Struts 2 : Hello World</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> </web-app>
- Now we will create a struts action class HelloWorld.java. To do this, create a new package tutorial under the project’s source folder and inside the tutorial package, create a new class file and name it HelloWorld.java. Below is the source code for this class file.
package tutorial; import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { private static final long serialVersionUID = 1L; private String message; public String execute() { setMessage("Hi there! This is a warm hello from Struts 2"); return SUCCESS; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } } - Notice that above class extends
ActionSupportand it implements theexecute()method. As per Struts 2, any class which does these two things are considered as Struts action classes. - We have our action class is ready. Now it’s the time to create the presentation page, i.e JSP. Create a new JSP file HelloWorld.jsp inside the WebContent folder and type in below code in this JSP file.
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Struts 2 - Hello World tutorial</title> </head> <body> <h2><s:property value="message"/></h2> If you can see above message, Congrats! You have successfully created your first Struts 2 application. </body> </html>
- Now we will create the very important struts.xml file which glues our action class with the presentation JSP file. Since Struts 2 requires struts.xml to be present in classes folder, we will create stuts.xml file inside the source folder, so that when building the WAR file, struts.xml will be put in classes folder. Below is the code for struts.xml file.
<?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" /> <package name="tutorial" namespace="/" extends="struts-default"> <action name="HelloWorld" class="tutorial.HelloWorld"> <result>/HelloWorld.jsp</result> </action> </package> </struts>
- Now we are good to go. Right click on the project name and click Export ? WAR File. Then deploy this WAR in the Tomcat’s webapps directory. Now start Tomcat server and point your browser to the URL http://localhost:8080/HelloWorld/HelloWorld.action and Tada! Your first struts 2 application is delivering the JSP page with a hello message to you!!
So, that’s it. Now the Hello World application is done using this latest Struts framework.



{ 76 comments… read them below or add one }
Excellent starting point buddy. You are right, existing examples are pretty confusing. Your article is simple, precise. Thanks
Thanks Amit!
Thanks a lot!!!!!!!!!!!!!!!
was very useful…………..
You are welcome, Priya!
Thanks Veerasundar. This was very helpful
///Thanks Veerasundar. This was very helpful//
Thanks Neena!
I tried this Sample code in following Config.
Eclipse, tomcat 5.0, jre 1.5
I deployed this sample application WAR file into tomcat.
I have tried to launch this by typing its url as
http://localhost:8080/HelloWorld
but it was showing Error as below -
type Status report
message /HelloWorld/WEB-INF/web.xml
description The requested resource (/HelloWorld/WEB-INF/web.xml) is not available.
Hi Atul,
The error you got is possibly because of (as the error message says) the web.xml may not be present in the WAR file that you had deployed. Can you please check your WAR file to see whether the web.xml present inside the WEB-INF folder?
Yes this war files contents web.xml.
i tried this example 3 – 4 time from scratch.
but each time i get same error.
Actually i put struts.xml file into WEB-INF folder.
but i seen in some example it is with scr files.
after that i tried this also but i get an error :-
resource is not available.
wht should i do.
i think some libraries are required in tomcat to read and convert these xml files.
Thanks Veer, I am able to run my fist struts 2 application. That was an excellent starting point.
Atul,
Open the Manager console in Apache Tomcat server and see the status of the struts application. If it is false, then the web application is not deployed correctly and some problem with the application WAR itself. If it is the error with any Java files, then the IDE would have shown at the compilation time itself, but if there is any error with web.xml or struts.xml, then IDE won’t show any errors, but application won’t be deployed in Tomcat. Please check if there is any syntax error with xml files.
Hi Mahesh,
Thanks for your feedback.
Hi Mahesh,
Thanks for your feedback.
thanx man,
thanx man,
i need some help form u. i normally tried ur application
1)i created the HelloWorld folder
in that i created src folder and WEB-INF folder and Helloworld.jsp placed in same folder
and then
2) in WEB-INF folder i placed web.xml and lib and i placed all neccessary jar files.
3) in src folder i placed the HelloWorld.java and struts.xml
i run the appl it showing 404 status error . i am running the appl in tomcat5.5 and i checked the web.xml and struts.xml it shows correctly .where i gettong the probelm i don’t no..
Normally in struts1.1 we placed the strut.xml placed parallel to web.xml . here we have to place in src folder i dont know just i am asking.
in previous u told that checked in tomcat manager i checked there it showing false but i checked all directory twice but it showing error. even i compile i try to compile to java file it shows error ActionSupport .
i hope u understood my probelm. i hoping positive response from u.
Thanks
Lakshman
Hi,
I have tried deploying your application exactly the way you have told but when I run it using Tomcat6.0.I am getting HTTP error saying HelloWorld.action resource not found.I checked struts.xml and web.xml again.It seems to be fine.My folder strusture is exactly the same as u have shown in ur UI view.Could you please tell me what exactly is the problem?Even if I try to just run HelloWrold.jsp it sayd HelloWorld.jsp not available.I’ll be thankful if you could help me.
Arti
Hi Lakshman, Arti
I couldn’t able to figure out the issue from your questions. Anyhow, please check the below points once again, just to make sure that everything is fine.
1. Check the placement of struts.xml. In Sturuts2 its placed inside the “source” folder.
2. Check the action declaration in struts.xml file.
3. Check if the “struts2″ filter and filter mapping defined correctly in “web.xml” file.
As said, I can’t figure out the exact issue just by looking at your questions. So, if possible, can you please send your files to my email id (available in the contact page), so that I can have a look at it and get back to you?
HTTP Status 404 – /HelloWorld/HelloWorld.action
——————————————————————————–
type Status report
message /HelloWorld/HelloWorld.action
description The requested resource (/HelloWorld/HelloWorld.action) is not available.
——————————————————————————–
Apache Tomcat/5.5.17
i am getting this error page. could you please tell me why it is happing so.
Thanks, works good (if you stick to the names…
.
BR,
Hansi
Hi shankar
i posted my application but i didn’t get the Response form u. when the Run the Application in server console i getting the following error .
pr 2, 2009 10:48:54 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:Program FilesJavajre1.5.0_14bin;.;C:WINDOWSsystem32;C:WINDOWS;E:Program FilesJavajre1.5.0_14binclient;E:Program FilesJavajre1.5.0_14bin;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:Program FilesTortoiseSVNbin;E:Program FilesJavajdk1.5.0_14bin;.;E:Program Filesapache-ant-1.7.1bin;.;
Apr 2, 2009 10:48:54 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 2, 2009 10:48:54 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 672 ms
Apr 2, 2009 10:48:54 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 2, 2009 10:48:55 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Apr 2, 2009 10:48:55 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Apr 2, 2009 10:48:55 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:207)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:302)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:78)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3635)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4222)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
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:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Apr 2, 2009 10:48:55 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Apr 2, 2009 10:48:55 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/HelloWorld1] startup failed due to previous errors
Apr 2, 2009 10:48:55 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 2, 2009 10:48:55 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 2, 2009 10:48:55 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Apr 2, 2009 10:48:55 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Apr 2, 2009 10:48:55 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 671 ms
i pasted the server log error to u. Every thing i checked the staging directory it is fine but where it getting error still i didn’t find . if it possible to u check my application , which i already send to u and solve my problem.
Waiting a positive Response from u.
Regards
Lakshman
Hi,
I am not able to deploy my HelloWorld.war into Webapps in Tomcat.It is not showing any error messages.I am new to Struts,please help me!
Thanks,
Prathibha
Hi Lakshman,
Firstly, I am not Shankar. I am Sundar.
Regarding the error you are getting, I just googled for the error message and it look’s like the error message is not a serious one. Please check this thread : http://www.coderanch.com/t/85960/ApacheTomcat/Tomcat-Native-library-not-found
Please follow the names I’ve given in my examples so that the code works fine (Pleas refer Hansi’s comment in the comment section of this blog post!). I was kinda busy with my work these days, didn’t get time to go through your code.
If you need any urgent assistance in Struts 2, try posting your query in forums like JavaRanch or Struts mailing archives
Have a nice day!
Hi Prathibha ,
Got your email. Glad that my tutorial helped you.
Thanks.
I tried a lot of examples but very confusing… and didn’t worked out.
Fortunately, I found this site. Thanks man, nice work. keep it up
i followed ur tutorial.. but when to view in browser. it not appear..
error displayed
”
type Status report
message There is no Action mapped for namespace / and action name HelloWorld.
description The requested resource (There is no Action mapped for namespace / and action name HelloWorld.) is not available.
”
what i need to do??
i used tomcat.. cant to..
i used jboss.. also cant..
7.Now we will create the very important struts.xml file which glues our action class with the presentation JSP file. Since Struts 2 requires struts.xml to be present in classes folder, we will create stuts.xml file inside the source folder, so that when building the WAR file, struts.xml will be put in classes folder.
Actually i need create struts.xml at where folder??
A) HelloWorld -> struts.xml
B) HelloWorld -> JavaResources : source -> tutorial -> struts.xml
C) HelloWorld -> WebContent -> struts.xml
im really confusing… i use eclipse.. but i cant create file in the answer B..
Hi Kvic,
If you look at the directory structure diagram (http://veerasundar.com/blog/wp-content/uploads/2008/11/struts-2-folder-structure.png), you can see that the struts.xml file is placed under the source folder. The point here is struts.xml file should be present in the classpath.
So, to create a XML file in eclipse, in Project explorer view, right click on your project’s source folder and click New -> File and give the file name as “struts.xml”.
I hope this helps.
im so careless.. actually my problem got solution.
should be like this for struts.xml
HelloWorld -> JavaResources : source -> struts.xml
i used jboss.
thanks.. this tutorial.. so easy to follow.. so easy to understand the concept..
thanks alot…
i hope got tutorial for the better practise..
this is the nice one.
but people who are using jboss. you have to add jboss-web.xml, under webinf directory. der u need to add context path. using that u have to trigger d url.
jboss-web.xml
login
url
http://localhost:8080/login/example/Login.action
regards,
karthik.
Can you please add a sample jboss-web.xml?
–
Regards,
Dwarak
Thanks for such a nice and quick explanation.
I was just going to copy/paste my error log and then, thought of giving one more try from scratch…..And, this helped me… I am very very new to struts itself.
This tutorial was the best I have ever found. Thanks.
Can you please explain, how can you access property values from JSP?
Thanks a lot.
Thanks for your feedback, Manasvi!
//Can you please explain, how can you access property values from JSP?//
If you want to load a properties file in JSP page, it requires adding a Java code to the JSP file, which is like adding business logic in the presentation layer. But this is not a good practice. So, it is good to load the properties file in your servlet and pass the values to your JSP page.
Have a look at this link on how to smartly load properties file in Java.
I hope this helps.
cheers.
I created the project in the same way as described in the tutorial, but I am not able to see the “message” property set in Action class. And, JSP is displayed perfectly without any errors. Any clues?
Thanks.
Hi Manasvi,
There is a setter method for the ‘message’ property in the ‘HelloWorld’ action class. This is how the message value is passed on to the JSP page.
Ok. Thanks. I got it working now.
Hay.. Thank you for your nice tutorial. Its really east, and I just done it. Hope more tutorials form you…
Enjoy Madi.
hi all:
first I imported latest struts-2.1.6 release jar file. Tomcat cannot deploy my application. after I changed jar file to struts-2.0.14, all worked fine . If your Tomcat cannot deploy your application, try to change your jar files version. This may help..
thanks this tutorial.
kind regards:
Jim
I had the same issue as many here: The resource xxx was not available.
I looked into the Tomcat’s log and found that the origin of the problem was:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileUploadException
So, I copyied the commons-fileupload-1.2.1.jar file found in the struts-2.1.6.zip (under the lib directory) to the proyects WEB-INF/lib and it worked.
Hope that helps anyone!
hi atul m getting the same error as you got. can you or any one else help me out.
thanx in advance
Hi,
I was able to successfully read the message when I accessed http://localhost:8080:HelloWorld/HelloWorld.jsp
and not http://localhost:8080/HelloWorld/HelloWorld.action. The latter throws up an error.
Anyone care to point out the difference ?
Thanks
First of all if you call the JSP page you will get an incomplete output “If you can see above message, Congrats! You have successfully created your first Struts 2 application. ”
but the expected output is “Hi there! This is a warm hello from Struts 2
If you can see above message, Congrats! You have successfully created your first Struts 2 application. ”
if you call the JSP file directly it is just like calling a static page( which in any production environment will be blocked by using filters if it is a workflow based app)
From most of the comments i feel that you didnt notice a slight mistake in the program.
You should specify /HelloWorld.jsp in the struts.xml instead of
/HelloWorld.jsp
(also in the POJO class it should be return “SUCCESS”; instead of return SUCCESS;)
Also for the people who get class not found exceptions, make sure that you added the jar files into lib folder.
Sorry for the typo
the change in struts.xml is
;< result name=”SUCCESS” >
Just a heads up here….at first I couldn’t get this to work because I had struts 2.1.x as my struts package.
Make sure you are using some variant of 2.0.x
Best wishes…
To people who had a problem with missing resource, the problem could also be that you have additional jars in your lib folder (like struts1-core.jar). So make sure that only struts2 jars are present.
Great tutorial!
HI
im trying to run the above program, but it is not working properly. can any one solve my problem
hi,
can you give us more details on the error that your are getting?
Hiii, m getting the following message
HTTP Status 404 – /HelloWorld/
——————————————————————————–
type Status report
message /HelloWorld/
description The requested resource (/HelloWorld/) is not available.
——————————————————————————–
Apache Tomcat/5.0.28
Hi VS. Nice tutorial. I am 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
javax.servlet.ServletException: org.apache.jasper.JasperException: Unsupported encoding: UTF-8
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
root cause
org.apache.jasper.JasperException: Unsupported encoding: UTF-8
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
org.apache.jasper.compiler.JspUtil.getReader(JspUtil.java:1091)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:250)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:120)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:165)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
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)
Hi Digant,
Which server are you using? Is it Tomcat?
Yes Veera, I am using tomcat 6
hi veera,
You are not showing the true struts 2 capability through this example. This example shows incomplete flow of struts 2. Rather you should have a starting jsp with textfield called message where the user enters the message say “Hi how are you” and this textfield should be mapped to the property message in the HelloWorld action class. then this message must be displayed on the result jsp. can you just modify this exmaple to show the complete flow
Hi Raghav,
The objective of this tutorial was to to cover the basic Struts flow. But, as you said, this example covers one way of the struts flow only.
Will follow up with this and will put up a detailed Struts 2 tutorial soon. Keep watching this space!
Thanks for paying heed to my suggestion. because you are really interested in creating a good resource for struts 2. I would like to give you a very good suggestions.
Creating a simple Struts 2 app is easy and there are lots of resources that provide this info. Modify your blog to provide information on “Struts2 Basics : Most Common Errors,Exceptions and Issues”
For example i dont know of a single person who has not faced one of the following errors
1. There is no Action mapped for namespace and action name …
2. Error FilterStart
3. Binding Error
. . . and several other. It is these issues that waste lot of time and people keep looking on the web for explanation for the these issues rather than the theory behind how Struts 2 works.
Try to create a small application using each of the tags and try finding out what error you faced. note down all the errors and thier solution. In the space where you provide data about “how to do” also provide information about “What not to do” i.e. things that will cause the identified errors. This is how you are educating the reader towards creating applications faster without loosing time on troubleshooting code.
Thanks and a good effort
hello,
i am using glassfish server to develop a simple struts2 application, i want to know the exact location of struts.xml file to be placed in my project. am using netbeans ide. with the normal creation of struts2 application, struts.xml file is getting generated in web-inf folder. But in some example application of struts2 with netbeans it is getting created in src folder . the example is working fine. but if i create any new applicaton with default settings, am getting 404 errror specifying not found for the specified action. if i copy the struts.xml to src folder, while deployment am getting error as:
WebModule[/Sample]PWC1270: Exception starting filter struts2
java.lang.NullPointerException
at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209)
at com.opensymphony.xwork2.util.FileManager.fileNeedsReloading(FileManager.java:60)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:325)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:168)
at com.opensymphony.xwork2.config.ConfigurationManager.conditionalReload(ConfigurationManager.java:220)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:61)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:774)
at org.apache.struts2.dispatcher.ng.InitOperations.initStaticContentLoader(InitOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:49)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:385)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:119)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4498)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5317)
at com.sun.enterprise.web.WebModule.start(WebModule.java:353)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:989)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:973)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:704)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1627)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1232)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:1005)
at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:992)
at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:470)
at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:182)
at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:308)
at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:231)
at com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:298)
at com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:132)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:966)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:609)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:653)
at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsConfigMBean.java:773)
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:597)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:381)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:364)
at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:477)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
at $Proxy1.invoke(Unknown Source)
at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174)
at com.sun.enterprise.admin.jmx.remote.server.callers.InvokeCaller.call(InvokeCaller.java:69)
at com.sun.enterprise.admin.jmx.remote.server.MBeanServerRequestHandler.handle(MBeanServerRequestHandler.java:155)
at com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.processRequest(RemoteJmxConnectorServlet.java:122)
at com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.doPost(RemoteJmxConnectorServlet.java:193)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:116)
. plz help me out in tracking where am wrong !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
struts2 expects the struts.xml to be there in the classpath. so try placing the sturts.xml inside the source folder.
thanks a lot…..very good tutorial….
Hi,
thanks for the tips!..
but it does not work for me.. I meant: I did not see the words: “Hi there! This is a warm hello from Struts 2″
could you please help?
thanks & regards
Luc
can u please explain a bit more about the issue that you are facing? Any stack trace?
Thanks for your response,
problem:
I am unable to see the words: “Hi there! This is a warm hello from Struts 2?
I am using Netbeans 6.9
when I set the welcome-page to the HelloWorld.jsp .. it does not show the words “Hi there! This is a warm hello from Struts 2?
my struts.xml:
/example/HelloWorld.jsp
;
and If I removed the welcome-page .. and I point my browser to: http://localhost:8080/webapplication1/doHelloWorld.action
I got message below:
“HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
GlassFish v3″
Thanks for your response,
problem:
I am unable to see the words: “Hi there! This is a warm hello from Struts 2?
I am using Netbeans 6.9
when I set the welcome-page to the HelloWorld.jsp .. it does not show the words “Hi there! This is a warm hello from Struts 2?
my struts.xml:
/example/HelloWorld.jsp
;
and If I removed the welcome-page .. and I point my browser to: http://localhost:8080/webapplication1/doHelloWorld.action
I got message below:
“HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
GlassFish v3?
hi,
I am new to struts and I tried your code. It is working but the message
is not displaying.
I’m able to see “If you can see above message, Congrats! You have successfully created your first Struts 2 application”.
Any idea why the message in the tags not dispaying.
I got the error. Now it’s working.
Finally an example that actually works! Thanks a lot!
Thank you soooooooo much! you just made my day……..thanks again
can any one give me his number so that i can call him or her in regards with struts2 ……………..I need urgent help regards with struts 2 because i am running struts 1 and its running well,but when i am trying 2 run struts 2 program its not running at all and i am getting tensed……
Hello Sir,
Great Tutorial…………. I ran in first attempt……………
Thank you !
I followed steps but got this output in browser:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Filter execution threw an exception
root cause
java.lang.NoClassDefFoundError: Could not initialize class com.opensymphony.xwork2.util.profiling.UtilTimerStack
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:425)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Thanks in advance..
problem:
I am unable to see the words: “Hi there! This is a warm hello from Struts 2?
i followed the same steps… but i am clueless what is going wrong here
Nice article. Everything worked fine for me using Eclipse Helios and tomcat 7. I first installed the JBoss Struts tools and AS tools into eclipse, and created a new project, and a new app server for tomcat 7. I downloaded Struts (everything) and unzipped struts2-blank.war, then copied everything in the lib directory to the lib directory of my project. I copied the contents of the different xml files from this site into TextPad, and then saved them to the right directory. The last file, had > instead of >, and so I changed that. I can’t think of anything else I did that was different.
Really Usefull.Thnk u:)
Thanks…Veera Sundar…Its working..People who are getting error resource not found just delete all the jar files except mentioned in this tutorial like … commons-logging-1.0.4.jar, freemarker-2.3.8.jar, ognl-2.6.11.jar, struts2-core-2.0.11.jar, xwork-2.0.4.jar also try to include jar file commons-fileupload-1.2.2.jar.
It works fine then…
im trying to start server bt this error occurs plz suggest smthng to get out of it n run my project:
25 Apr, 2012 4:42:12 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 (x86)\Java\jdk1.6.0\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jdk1.6.0/bin/../jre/bin/client;C:/Program Files (x86)/Java/jdk1.6.0/bin/../jre/bin;C:/Program Files (x86)/Java/jdk1.6.0/bin/../jre/lib/i386;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files (x86)\Common Files\ArcSoft\Bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Dell\DW WLAN Card;c:\Program Files\WIDCOMM\Bluetooth Software\;c:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Rational\common;C:\Program Files (x86)\Java\jdk1.5.0_08\bin;C:\driver;C:\Program Files (x86)\Java\jdk1.6.0\bin;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby1.8.7\bin;C:\BC5\BIN;E:\SONAL’S DOC\BMC-MAC\softwares\eclipse-jee-helios-SR2-win32\eclipse;
25 Apr, 2012 4:42:12 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:HelloWorld’ did not find a matching property.
25 Apr, 2012 4:42:12 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
25 Apr, 2012 4:42:12 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8080"]
25 Apr, 2012 4:42:12 PM org.apache.coyote.AbstractProtocol init
SEVERE: Failed to initialize end point associated with ProtocolHandler ["ajp-bio-8080"]
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.(ServerSocket.java:185)
at java.net.ServerSocket.(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:369)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:553)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:369)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:937)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:781)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.startup.Catalina.load(Catalina.java:573)
at org.apache.catalina.startup.Catalina.load(Catalina.java:598)
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:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:449)
25 Apr, 2012 4:42:12 PM org.apache.catalina.core.StandardService initInternal
SEVERE: Failed to initialize connector [Connector[AJP/1.3-8080]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[AJP/1.3-8080]]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:781)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.startup.Catalina.load(Catalina.java:573)
at org.apache.catalina.startup.Catalina.load(Catalina.java:598)
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:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:449)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:939)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
… 12 more
Caused by: java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.(ServerSocket.java:185)
at java.net.ServerSocket.(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:369)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:553)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:369)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:937)
… 13 more
25 Apr, 2012 4:42:12 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 413 ms
25 Apr, 2012 4:42:12 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
25 Apr, 2012 4:42:12 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.23
25 Apr, 2012 4:42:12 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
25 Apr, 2012 4:42:12 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 568 ms
25 Apr, 2012 4:42:13 PM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command ‘GET / HTTP/1.1′ received
Nice poc..Really helpful for beginers of struts 2.0.Please post if you know anything about iterceptor with such a nice description
Here we are using filter.can u tell me what is the reason behind it and without using filterit is running or not.
Thanks sir…can we run this directly from eclipse?