Skip to main content

Struts 2 Hello World Example

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

Comments

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

    ReplyDelete
  2. 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).

    ReplyDelete
  3. Thanks for your compliments. In future you will found more examples

    ReplyDelete
  4. Hi
    Thanks 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

    ReplyDelete
  5. 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.
    If 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

    ReplyDelete
    Replies
    1. Exactly !

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

      Delete
  6. Hi ,
    im getting blank page if i deployed and executed the first sample,im new to struts2 ,i dont know how to run the sample

    ReplyDelete
  7. Hi Vinod,
    Thanks a lot.I will try this as I m struggling to run the example from roseindia ...
    this looks easier.

    ReplyDelete
  8. Hi,

    It 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?

    ReplyDelete
  9. I am sure to write an ant build file to deploy it

    ReplyDelete
  10. I am not able to test the basic application described above. Is the directory structure correct? How to go about using MyEclipse?

    ReplyDelete
  11. Hi Sam
    If 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

    ReplyDelete
  12. Hi. This example does not work for me. I get the following error :
    SEVERE: 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

    ReplyDelete
  13. Hi
    You 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

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

    ReplyDelete
  15. Hi Vinod,
    Am 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

    ReplyDelete
  16. Hi All
    If 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

    ReplyDelete
  17. This is just what I want.:)

    ReplyDelete
  18. Hi,

    a 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

    ReplyDelete
  19. add listener tag no problem occur regarding
    SEVERE: Exception starting filter struts2

    ReplyDelete
  20. Add Listener Tag for the problem
    SEVERE: Exception starting filter struts2

    ReplyDelete
  21. Hi,
    while 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

    ReplyDelete
  22. yeah ..its working fine for me.
    thanks Vinod ,thnx a lot man.
    Regards,
    Ram

    ReplyDelete
  23. thx from Belarus :)

    ReplyDelete
  24. This simple helped a lot, thanks Vinod.
    Struts 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.

    ReplyDelete
  25. hi Vinod,
    Its very simple,straight forward and lucid...
    Nice work man keep it up.
    sincerely
    kaasi

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

    http://www.howtodothings.com/computers-internet/how-to-create-struts-2-helloworld-on-eclipse

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

    ReplyDelete
  28. how to build WAR file?

    ReplyDelete
  29. Hi... 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:
    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.

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

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

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

    ReplyDelete
  32. Hi Vinod,

    I Really appreciate your help.



    siraj

    ReplyDelete
  33. Hi Vinoth ,

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

    ReplyDelete
  34. 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 ?
    error :

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

    ReplyDelete
  35. Hi Praveenkan,

    It 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,

    ReplyDelete
  36. hi. i am getting file /struts-tags not found error in jsp. what do i do?

    ReplyDelete
  37. This is the only example I've found that is written correctly and works. Many thanks for a job well done!

    ReplyDelete
  38. I was finding the struts2 in action example difficult to work with.Yours helped me understand it better.Thanks Vinod

    ReplyDelete
  39. hi 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 :
    SEVERE: 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)

    ReplyDelete
  40. Hi,
    I am following error while running this code:
    org.apache.jasper.JasperException: File "/struts-tags" not found.

    What should I do?

    ReplyDelete
  41. I am quite new in Struts2
    need 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)

    ReplyDelete
  42. Hi Gladiator,
    Please see my comment.

    http://javachamp.blogspot.com/2008/07/struts-2-hello-world-example.html?showComment=1217041620000#c6013855066956126525

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

    ReplyDelete
  44. Hi,
    I think you haven't put your struts.xml file at right place. Please put that in classes folder

    ReplyDelete
  45. "Sun Certified Java Programmer" how did you get that certification........

    ReplyDelete
  46. HI Vinod

    I 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

    ReplyDelete
  47. Hey
    There must be a error on the back end. Please check

    Vinod

    ReplyDelete
  48. hello all,

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

    ReplyDelete
  49. hi,

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

    ReplyDelete
  50. You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse

    ReplyDelete
  51. Hi,
    Thanks,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. :(

    ReplyDelete
  52. java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
    at 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

    ReplyDelete
  53. please tell me y its giving error

    ReplyDelete
  54. am sudhakar tell me the solution for the above problem

    ReplyDelete
  55. very new to struts...

    tried 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

    ReplyDelete
  56. You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse

    ReplyDelete
  57. Thanks 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?

    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

    ReplyDelete
  58. Thanks for ur example. while running ur example program in eclipse i got this error ....
    Status 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.

    ReplyDelete
  59. 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 )
    Mudassar
    hakim-mudassar@rediffmail.com
    hakim-mudassar.8k.com

    ReplyDelete
  60. Hi Vinod!

    Your 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

    ReplyDelete
  61. Hi Vinod,

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

    ReplyDelete
  62. Hi Vinod,

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

    ReplyDelete
  63. in my struts 2 application finding following error please send what it mean/problem

    Class: com.opensymphony.xwork2.spring.SpringObjectFactory
    File: SpringObjectFactory.java
    Method: getClassInstance
    Line: 209 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1

    ReplyDelete
  64. Hi Vinod, can you please help me with error the I posted earlier? Thanks.

    ReplyDelete
  65. Hi, Tony. I had that problem.
    SEVERE: 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

    ReplyDelete
  66. Hi, Tony. I had that problem.
    SEVERE: 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

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


    Sridhar.ch

    ReplyDelete
  68. Thanks Max,
    Your response helps me a lot
    :-)

    ReplyDelete
  69. real culprit in following error
    "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

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

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

    ReplyDelete
  71. I am getting 404 error can u help me??

    ReplyDelete
  72. very practical and useful; exactly what I needed. Thank you!

    ReplyDelete
  73. hi am new to struts when i run above struts example i will get fallowing error eclipse can u help me....


    type Status report

    message

    description The requested resource () is not available.

    ReplyDelete
  74. Iam getting these error. PLease help me

    SEVERE: 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)

    ReplyDelete
  75. This tutorial just contain the source codes it is not provided how to do things. Good working tutorial but try to specific

    ReplyDelete
  76. show Pagination examples with efficient process with hibernate and google ui paginations ways

    ReplyDelete
  77. I got this error when running this application..Plz help me..

    type Status report

    message

    description: The requested resource () is not available.

    ReplyDelete
  78. Nice blog and nice program also. I would like to share some of my java programs too.

    http://java-program-sample.blogspot.com

    ReplyDelete
  79. Hi Vinod,
    Thnx 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.

    ReplyDelete
  80. Hey Kartik,

    I 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

    ReplyDelete
  81. Hi Vinod,
    Thnx 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...

    ReplyDelete
  82. I have just one more doubt...
    Since 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.

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

    ReplyDelete
  84. Hi Sr,
    I 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.

    ReplyDelete
  85. Hi DineshRam,
    I 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.

    ReplyDelete
  86. Hello Tony,

    I have exactly the same problem like you.
    Did you solve your problem?
    if yes, how do you process to solve it?

    Thx

    ReplyDelete
  87. Hi Vinod,
    Thanks for ur example, It's very useful for struts2 freshers...

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

Post a Comment

Popular posts from this blog

Getting height and width of image in Java

Yesterday I was working on something that requires manipulation of image for getting its properties. After searching over the internet I found a very intersting class on Java i.e ImageIO and BufferedImage class. These classes are good enough to manipulate images. there are many other claases also. But what I need i got it from these. I found many developers searching over internet for getting properties of image and there is no good small example for that. Thats why I thought why not creating a simple code to manipulate the image and help the developers. Here is the small code that helps to get the height and width of the image. Enjoy it!! import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class GetImage { public static void main(String[] args) { try { File f = new File("E:/Vinod/Docs/Pics/krishna_01.jpg"); BufferedImage image = ImageIO.read(f); int height = image.getHeight(); in

SSL in Spring Boot using GoDaddy certificate on EC2

In this article, we will be going to see how we can achieve the HTTPS in the spring boot application . You will get lots of items on how to use the self-generated certificate with Spring Boot. But today we are going to use the CA generated certificates with the Spring Boot so that our application will work on HTTPS. We need the following things to work: CA certificates including, private key and certificate. In this article, we are using the GoDaddy wild card certificate. Spring Boot application OpenSSL library Convert the certificate and private key to PKCS 12 First of all, we need to convert the CA certificate to .p12 format . We need to have OpenSSL on the system to work with command. Also, we need to have all files in the same directory where we are running this command. The command required to covert the same: openssl pkcs12 -export -in [ceritificate-name] -inkey [private-key] -name [host] -out [new-file.p12] Here replace the values: [ceritificate-name] with