I had seen many new deveopers struggling against struts2 hello world example. So I decided to write a small example.
Below are the required libraries to run this example which are easily availabel
struts2-core-2.1.8.1
xwork-core-2.1.6
commons-logging-1.0.4
commons-logging-api-1.1
freemarker-2.3.8
ognl-2.7.3
commons-fileupload-1.2
The structure of the applictaion which I am following is (Eclipse IDE)
Struts2Demo
|---src
| |----org
| | |----vinod
| | | |----action
| | | | |----HelloWorld।java
|---struts.xml
|---WebContent
| |---jsp
| |---HelloWorld।jsp
|---index.jsp
|---WEB-INF
| |---lib
| |---web.xml
It is true that different IDE's use different structure, but at last when war is build they follow same structure.
Lets start...
HelloWorld.java
Struts 2 ajax drop down example
Struts 2 change <actionerror /> <actionmessage />
Struts 2 Session Check Interceptor
About Struts 2
Below are the required libraries to run this example which are easily availabel
struts2-core-2.1.8.1
xwork-core-2.1.6
commons-logging-1.0.4
commons-logging-api-1.1
freemarker-2.3.8
ognl-2.7.3
commons-fileupload-1.2
The structure of the applictaion which I am following is (Eclipse IDE)
Struts2Demo
|---src
| |----org
| | |----vinod
| | | |----action
| | | | |----HelloWorld।java
|---struts.xml
|---WebContent
| |---jsp
| |---HelloWorld।jsp
|---index.jsp
|---WEB-INF
| |---lib
| |---web.xml
It is true that different IDE's use different structure, but at last when war is build they follow same structure.
Lets start...
HelloWorld.java
import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { String greetings = null; public String execute() throws Exception { setGreetings("Hello World"); return SUCCESS; } /** * @return the greetings */ public String getGreetings() { return greetings; } /** * @param greetings * the greetings to set */ public void setGreetings(String greetings) { this.greetings = greetings; } }HelloWorld.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Struts 2 Example</title> </head> <body> <s:property value="greetings"> </s:property></body> </html>index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Struts 2 Example</title> </head> <body> <s:action executeresult="true" name="HelloWorldAction"></s:action> </body> </html>struts.xml
<struts> <package extends="struts-default" name="hello"> <action class="org.vinod.action.HelloWorld" name="HelloWorldAction"> <result>/jsp/HelloWorld.jsp</result> </action> </package> </struts>web.xml
<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemalocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>Enjoy the struts2 (most popular java framework today) I had also written some more examples and some solutions of struts which can be easily found at
Struts 2 ajax drop down example
Struts 2 change <actionerror /> <actionmessage />
Struts 2 Session Check Interceptor
About Struts 2
Nice,It is very convenient for me to make a first hand example on struts2 with this example. I love your example and follow your blog in future for other references too.
ReplyDeleteThanks
Thank you for this example. It is the only example I've found that actually works as described (and that includes the examples found at the Apache Struts 2 website).
ReplyDeleteThanks for your compliments. In future you will found more examples
ReplyDeleteHi
ReplyDeleteThanks for your neat examples.But i have 2 issues
1. Once i startup the tomcat 6.0.16 from eclipse 3.3.0, i got the following error.
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
2. I found some error prone in jsp
Cannot find the tag library descriptor for /struts-tags in JSP. It is shown in Jsp file with error sign at the particular line no.
Kindly let me know idea
This error sometimes come due to reason that you haven't placed your struts.xml in right place. If it doesn't work then check that it is in classes folder or not. If not place it there and restart your server and then try again.
ReplyDeleteIf you copy the whole example line by line then it should work well. If you have done some modifications then check with above example
Hope, this will solve your problem
Exactly !
DeleteI did put the file in the correct place but with the wrong name! strust.xml insted of struts.xml. I just waist 4 hours trying to fix this.
Hi ,
ReplyDeleteim getting blank page if i deployed and executed the first sample,im new to struts2 ,i dont know how to run the sample
Hi Vinod,
ReplyDeleteThanks a lot.I will try this as I m struggling to run the example from roseindia ...
this looks easier.
Hi,
ReplyDeleteIt is a wonderful work!!! Keep it up.
Could you please write buil.xml file for ant so that one can build the project and deploy in the container?
I am sure to write an ant build file to deploy it
ReplyDeleteI am not able to test the basic application described above. Is the directory structure correct? How to go about using MyEclipse?
ReplyDeleteHi Sam
ReplyDeleteIf you are using MyEclipse no problem. Simply make a web application and put the required files in there respective folders and then deploy the application. However I am shortly giving an ant build for this example if above does not work.
This is very simple example and works well with most of the people
Hi. This example does not work for me. I get the following error :
ReplyDeleteSEVERE: Exception starting filter struts2
Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/C:/Apache%20Tomcat%206.0.16%20on%2010.156.0.195/webapps/struts2-blank-2.0.11.2/WEB-INF/lib/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72
Am I doing something wrong?
Please help. Thanks
Hi
ReplyDeleteYou got this error because you haven't placed your struts.xml in correct path or you haven't included all required libraries
You can mail me the code and I will see why there is a problem with you as nobody gets any problem
class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/C:/dev/INET_1_0/WebContent/WEB-INF/lib/struts2-core-2.0.11.1.jar!/struts-default.xml:30:72 - bean - jar:file:/C:/java/apache-tomcat-6.0.18/wtpwebapps/INET_1_0/WEB-INF/lib/struts2-core-2.0.11.1.jar!/struts-default.xml:30:72
ReplyDeleteHi Vinod,
ReplyDeleteAm getting the below error.Am using Eclipe 3.1.2,Tomcat 6.0.
WARNING: Settings: Could not parse struts.locale setting, substituting default VM locale
Sep 30, 2008 9:34:34 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
Action class [org.vinod.action.HelloWorld] not found - action - file:/C:/Program%20Files/Apache%20Software%20Foundation/tomcat-6.0.18/webapps/struts2demo/WEB-INF/classes/struts.xml:6:86
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:374)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:329)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:429)
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:201)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef
Hi All
ReplyDeleteIf you have any problems post them at:
http://www.nabble.com/Struts-2-f30929.html
Solutions of the most of the problems were given there. If you don't find your solution then you can write your problem. Many struts 2 developers will be available there
Thanks
This is just what I want.:)
ReplyDeleteHi,
ReplyDeletea great workin example (this the first one which works). Would you mind to explain how it works in detail. Why do you use two files index.jsp and HelloWold.jsp. If a touch one of them the example does not work anymore.
Thanks
Eduard
add listener tag no problem occur regarding
ReplyDeleteSEVERE: Exception starting filter struts2
Add Listener Tag for the problem
ReplyDeleteSEVERE: Exception starting filter struts2
Hi,
ReplyDeletewhile executing this example. it is showing
HTTP Status 404 - /struts2Demo/
--------------------------------------------------------------------------------
type Status report
message /struts2Demo/
description The requested resource (/struts2Demo/) is not available.
but if I will comment filter tag in web.xml it is working upto index.jsp........what should I do
Thanx in Advance,
Nitin
yeah ..its working fine for me.
ReplyDeletethanks Vinod ,thnx a lot man.
Regards,
Ram
thx from Belarus :)
ReplyDeleteThis simple helped a lot, thanks Vinod.
ReplyDeleteStruts 2.1.6,and i faced one exception, not able to load the struts-default.xml. Then I copied the jat commons-fileupload-1.2.1.jar to the lib folder and starts my application starts fine.
Very much thanks Vinod, and expects more ideas from your blog.
hi Vinod,
ReplyDeleteIts very simple,straight forward and lucid...
Nice work man keep it up.
sincerely
kaasi
I encountered error when I try to ran this sample. I didn't work! Anyway, thanks for the example. For sake of helping others. I compiled my own hello world that is up and running. You guys may want to take a look over this web page.
ReplyDeletehttp://www.howtodothings.com/computers-internet/how-to-create-struts-2-helloworld-on-eclipse
Hi, When i deploy my application in tomcat 6.0.18, am getting error as "Project folder" not found. but i have deployed correctly in webapps folder. Pls tel me wat to do?
ReplyDeletehow to build WAR file?
ReplyDeleteHi... I too am having trouble finding a working example of a simple struts2 app. I have tried this and I am getting the following error:
ReplyDeleteorg.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
Earlier, I posted a question. I think it may have been about "The Struts dispatcher cannot be found." Anyway, if it was, then the solution was because Eclipse was building the war file with the web.xml file in the wrong location. After the application deployed on my Tomcat 5.5.27 server, I moved the file to the correct folder and the problem is resolved.
ReplyDeleteThe big help to resolving this was the catalina.{date}.log file in Tomcat 5.5\logs directory. I had been focusing on another log, the localhost.{date}.log but that was a stack trace that gave no hint at the root cause.
Thanks for the demo.
I used eclipse and tomcat 5.5.25 at my development center and developed an application using struts 2, it works absolutely ok, but when i developed it on server supporting same tomcat it gave me error that
ReplyDeleteorg.apache.jasper.JasperException: File "/struts-tags" not found
Please help me to resolve this problem.
It works on my local PC, but does not work when application is hosted.
Hi Vinod,
ReplyDeleteI Really appreciate your help.
siraj
Hi Vinoth ,
ReplyDeleteHi got an error while invoking the page in browser:
The The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
hi Vinoth, i just referred you sample code for sample application in Struts 2. I wold like to know how to do the login application in struts 2. I have created the login.jsp with had a form action too. but when i cick submit button i getting the following error . what is reason i am getting this error and could you give an idea how to get input from the form and validate it ?
ReplyDeleteerror :
there is no action mapped for namespace / and action doLogin. [unknown location].
my package structure is here
-src
--com.sample.action
---LoginAction.java
--Struts.xml
-web
--WEB-INF
---web.xml
---lib
---view
----success.jsp
----login.jsp
----error.jsp
--META-INF
-index.jsp
please help me in this issue.. Thanks in advance...
Hi Praveenkan,
ReplyDeleteIt seems that there is some error in the mapping in the jsp file. I will be more sure about it if you send the code to me.
Thanks,
good, it is very helpfull to me
ReplyDeletehi. i am getting file /struts-tags not found error in jsp. what do i do?
ReplyDeleteThis is the only example I've found that is written correctly and works. Many thanks for a job well done!
ReplyDeleteI was finding the struts2 in action example difficult to work with.Yours helped me understand it better.Thanks Vinod
ReplyDeletehi vinod, great work, but i couldnt get it right.i think i placed struts.xml in the wrong folder, which is it? i get the error :
ReplyDeleteSEVERE: Could not execute action: /HelloWorldAction
There is no Action mapped for action name HelloWorldAction. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.components.ActionComponent.executeAction(ActionComponent.java:249)
at org.apache.struts2.components.ActionComponent.end(ActionComponent.java:155)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:43)
at org.apache.jsp.index_jsp._jspx_meth_s_005faction_005f0(index_jsp.java:89)
Hi,
ReplyDeleteI am following error while running this code:
org.apache.jasper.JasperException: File "/struts-tags" not found.
What should I do?
I am quite new in Struts2
ReplyDeleteneed your help!!!
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
Jan 28, 2010 4:03:02 PM 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: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)
Hi Gladiator,
ReplyDeletePlease see my comment.
http://javachamp.blogspot.com/2008/07/struts-2-hello-world-example.html?showComment=1217041620000#c6013855066956126525
i am trying to deploy the same example but getting "requested resource not found" error.. if i remove FilterDispatcher ebtry from web.xml and invoke simple jsp then application is running...please help
ReplyDeleteHi,
ReplyDeleteI think you haven't put your struts.xml file at right place. Please put that in classes folder
"Sun Certified Java Programmer" how did you get that certification........
ReplyDeleteHI Vinod
ReplyDeleteI have followed your structure format and file, after the deploying in to tomcat, When i try to hit URL the empty page is going
Could you help me regarding this.
Regards
C.Selvan
Hey
ReplyDeleteThere must be a error on the back end. Please check
Vinod
hello all,
ReplyDeleteDoes anybody know the following error? :(
-org.xml.sax.SAXParseException: Document root element "taglib", must match DOCTYPE root "null".
i think i should set "taglib" in web.xml to point from my jsp...
is it true? and how?
Thanks in advance...
hi,
ReplyDeletei am using struts2-core-2.1.6.jar. So struts-tags is in META-INF of the jar file...
But somehow it doesn't know where the lib file.
And I've also tried to put the tag-lib in WEB-INF of my application.
But it doesn't work.
Pls help...
You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse
ReplyDeleteHi,
ReplyDeleteThanks,Vinod.
Yes, the struts jar is in WEB-INF/lib.
It works fine with eclipse in my local pc.
But I need to deploy my application in SUN ONE web server in UNIX.
In SUN 1, it doesnt know the tag-lib. :(
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
ReplyDeleteat com.sun.faces.config.WebConfiguration.getServletContextName(WebConfiguration.java:221)
at com.sun.faces.config.WebConfiguration.(WebConfiguration.java:82)
at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:152)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:279)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
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:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
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:566)
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.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 12, 2010 10:46:32 PM org.apache.catalina.core.StandardContext start
please tell me y its giving error
ReplyDeleteam sudhakar tell me the solution for the above problem
ReplyDeletevery new to struts...
ReplyDeletetried to follow the steps, but, got the following error. Appreciate any guidance.
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
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.start(ContainerBase.java:1045)
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)
Jul 26, 2010 4:12:28 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Jul 26, 2010 4:12:28 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/HelloWorld] startup failed due to previous errors
=====
dir structure
HelloWorld
|---src
| |----org
| | |----vinod
| | | |----action
| | | | |----HelloWorld।java
|---struts.xml
|---WebContent
| |---jsp
| | |---HelloWorld।jsp
|---index.jsp
|---WEB-INF
| |---lib
| |---web.xml
You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse
ReplyDeleteThanks and I appreciate the prompt response Viond. I'm using Eclipse and have the following jars' added to the java build path. Is there anything else I can try?
ReplyDeletestruts2-core-2.1.8.1
xwork-core-2.1.6
commons-logging-1.0.4
commons-logging-api-1.1
freemarker-2.3.8
ognl-2.7.3
commons-fileupload-1.2
Thanks for ur example. while running ur example program in eclipse i got this error ....
ReplyDeleteStatus report
ERROR:::
message /Strusts2Demo/WEB-INF/classes/com/sriseshaa/test/HelloWorld.java
description The requested resource (/Strusts2Demo/WEB-INF/classes/com/sriseshaa/test/HelloWorld.java) is not available.
copy the jars manually & paste it in the web-in > lib folder in the eclipse editor apart from adding them in the build path ( which normally adds it in Java Resources> Libraries instead )
ReplyDeleteMudassar
hakim-mudassar@rediffmail.com
hakim-mudassar.8k.com
Hi Vinod!
ReplyDeleteYour code regarding Struts2 HelloWorld Eg. is very good. I have been strugling for such type of code in somany sites.
I tried ur code in Eclipse ..It is nice. I am a java beginer. This type of code encourages to learn more things..Thank You, Thanks a lot.
Sridhar
Hi Vinod,
ReplyDeleteThanks for the good example. Unfortunately I am not as lucky as some of the guys above and I wasn't able to get it to work. I tried many Struts 2 examples online but they all give me the following error message. Any Idea what this could be?
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Nov 7, 2010 5:17:31 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: Could not create JarEntryRevision for [jar:file:/Users/Payam_Home/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SupperLotto/WEB-INF/lib/struts2-core-2.2.1.jar]!
java.lang.NoClassDefFoundError: org/apache/commons/io/output/NullOutputStream
at com.opensymphony.xwork2.util.FileManager$JarEntryRevision.build(FileManager.java:307)
at com.opensymphony.xwork2.util.FileManager.loadFile(FileManager.java:145)
at com.opensymphony.xwork2.util.FileManager.loadFile(FileManager.java:105)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:898)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:154)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:121)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:179)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
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.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:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.NullOutputStream
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
... 30 more
I am using the following libraries:
Commons-logging-1.0.4.jar
freemaker-2.3.16.jar
ognl-3.0.jar
struts2-core2.2.1.jar
xwork-core-2.2.1.jar
Thanks for the help.
Tony.
Hi Vinod,
ReplyDeleteThanks for the great struts 2 example. Unfortunately I am not able to run it on my environment and I need your help. I tried many different examples online and I've been facing the same problem. Do you know what could be causing this?
NFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Nov 7, 2010 5:34:29 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: Could not create JarEntryRevision for [jar:file:/Users/Payam_Home/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SupperLotto/WEB-INF/lib/struts2-core-2.2.1.jar]!
java.lang.NoClassDefFoundError: org/apache/commons/io/output/NullOutputStream
at com.opensymphony.xwork2.util.FileManager$JarEntryRevision.build(FileManager.java:307)
at com.opensymphony.xwork2.util.FileManager.loadFile(FileManager.java:145)
at com.opensymphony.xwork2.util.FileManager.loadFile(FileManager.java:105)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:898)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:154)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:121)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:179)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
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.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:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.NullOutputStream
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
... 30 more
My libraries are:
Commons-fileupload.1.2.1.jar
Commons-logging-1.0.4.jar
commons-logging-api-1.1.jar
freemaker-2.3.16.jar
ognl-3.0.jar
struts-core-2.2.1.jar
xowrk-core-2.2.1.jar
Thanks for your help,
Tony.
in my struts 2 application finding following error please send what it mean/problem
ReplyDeleteClass: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 209 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1
Hi,
ReplyDeleteIt is Spring error
Hi Vinod, can you please help me with error the I posted earlier? Thanks.
ReplyDeleteHi, Tony. I had that problem.
ReplyDeleteSEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatche
I solved it due to unziping ..\struts-2.2.1\apps\struts2-blank-2.2.1.war from last struts2 downloading. After uziping you can see web.xml:
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
Also in ..\struts-2.2.1\apps\struts2-blank-2.2.1.war\WEB-INF\lib directory you can find the list of all needed libraries:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.16.jar
javassist-3.7.ga.jar
ognl-3.0.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
Hi, Tony. I had that problem.
ReplyDeleteSEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatche
I solved it due to unziping ..\struts-2.2.1\apps\struts2-blank-2.2.1.war from last struts2 downloading. After uziping you can see web.xml:
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
Also in ..\struts-2.2.1\apps\struts2-blank-2.2.1.war\WEB-INF\lib directory you can find the list of all needed libraries:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.16.jar
javassist-3.7.ga.jar
ognl-3.0.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
Hi Vinod. could you please write about interceptors of struts2 in detailed or else suggest some link. But your way of explation is good that y pls post it. I am a beginer . I had used ur hello world eg.. It was very nice. Previously I had posted one comment on oct 28
ReplyDeleteSridhar.ch
Thanks Max,
ReplyDeleteYour response helps me a lot
:-)
real culprit in following error
ReplyDelete"SEVERE: Exception starting filter struts2" is following string in struts.xml
"http://struts.apache.org/dtds/struts-2.0.dtd"
It requires internet access atleast once after that it runs fine without any internet access and untill netbeans is restarted. I faced this issue few times. -- Mandeep
Ok....I was able to debug major errors with some simple weird stuff which kind of makes sense to me now. First of all, I assume that you all are using the tomcat plugin to start and stop tomcat in Eclipse IDE.
ReplyDeleteErrors and how I resolved them:-
1. SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
Solution: I copied all the jars from struts2 showcase example app. Available here -> http://struts.apache.org/2.0.14/docs/tutorials.html
I copied all the jars in the web-inf/lib of that war to my web-inf/lib of eclipse project. Still got that error....on checking, I saw that the same server was being used by my previous versions which I removed by deleting that server and recreating in eclipse....made sure it did not reference my previous version's lib over my current lib by checking the runtime configuration for my project. Solved that particular error.
2. Then, got some spring errors like SpringObjectFactory not found and stuff
Solution: Deleted all the spring jars from my lib like spring-beans, spring struts plugin etc. Solved that particular error.
3. Then came the xwork2 errors -> com.opensymphony.xwork2.inject.DependencyException:
and some java runtime exceptions
Solution: You need to mention your action classes package in web.xml. Thanks to a mail archive...i could resolve it. Link -> http://mail-archives.apache.org/mod_mbox/struts-user/200908.mbox/%3CBLU142-W31D8183CCB7D6CABA09BFDAE080@phx.gbl%3E
You need to mention your action package like this in your web.xml:-
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
actionPackages
myapp.actions
Thats it. Its working now.
I am getting 404 error can u help me??
ReplyDeletevery practical and useful; exactly what I needed. Thank you!
ReplyDeletehi am new to struts when i run above struts example i will get fallowing error eclipse can u help me....
ReplyDeletetype Status report
message
description The requested resource () is not available.
Iam getting these error. PLease help me
ReplyDeleteSEVERE: Dispatcher initialization failed
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:295)
at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:431)
at com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:207)
at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
at com.opensymphony.xwork2.inject.ContainerBuilder$3.create(ContainerBuilder.java:93)
This tutorial just contain the source codes it is not provided how to do things. Good working tutorial but try to specific
ReplyDeletethank you budy
ReplyDeleteshow Pagination examples with efficient process with hibernate and google ui paginations ways
ReplyDeleteI got this error when running this application..Plz help me..
ReplyDeletetype Status report
message
description: The requested resource () is not available.
Nice blog and nice program also. I would like to share some of my java programs too.
ReplyDeletehttp://java-program-sample.blogspot.com
Hi Vinod,
ReplyDeleteThnx for the wonderful blog on Struts2. It is really good. But i am stuck up with one issue of
org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
Here
1. web.xml in rar is at proper location WEB-INF/web.xml .
2. Even the url mapping is /*.
3. The filter is "org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter"
4. I have used all the libraries same as you had mentioned and copied in lib folder as well.
5. Each and every code which you gave i copied and pasted on my eclipse project.
But it did not work.
Pls Help... I am doing lot of R&D on this and stuck from 3 days.
Hey Kartik,
ReplyDeleteI think you haven't put your struts.xml file at right place. Please put that in classes folder. You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse
Hi Vinod,
ReplyDeleteThnx for your update... I had not placed in struts.xml. I placed it in classes folder and now it is working fine... Thnx for your help...
I have just one more doubt...
ReplyDeleteSince this issue was not placing struts.xml at the ryt place... we should get an meaningful error msg. But here we get "The Struts dispatcher cannot be found." even though we provide web.xml properly.
It would be good if you can clarify this.
Error is OK.. when application tries to find the dispatcher it is not found on the location where it should be and hence the error.
ReplyDeleteHi Sr,
ReplyDeleteI got error my project(Struts2Demo) is not available.Even-though i followed u r program steps only. I am not at all change anything.Please help me.I hope u will reply.
Note:
1)In web.xml, i can run html file with out filter tags.But with filter tags
error.
2)In html file I cant use the struts tags also, In-case i use, Its showing error.
Thanks&Regards,
dineshram89@gmail.com,
9035297370.
Hi DineshRam,
ReplyDeleteI think you got an error like this :
org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
if yes...
please places your struts.xml file in the classes folder. I too faced the same problem..
Please see the previous comments.
Hello Tony,
ReplyDeleteI have exactly the same problem like you.
Did you solve your problem?
if yes, how do you process to solve it?
Thx
Hi Vinod,
ReplyDeleteThanks for ur example, It's very useful for struts2 freshers...
Nice tutorial using Struts 2 with good images. I have a Basic Struts Login Application program using Strus1.2. I think this will also very helpful to your blog followers.
ReplyDelete