0

I'm new with Struts2. I'm sorry but I've tried different solutions already suggested on StackOverflow,they didn't worked. I followed these tutorial's instructions:http://www.tutorialspoint.com/struts_2/ Can someone help me?

This is the error:

AVVERTENZA: Could not find action or result: /HelloWordStrut2/hello?name=aaa
There is no Action mapped for namespace [/] and action name [hello] associated with context path [/HelloWordStrut2]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

This is my workspace:

Workspace

My struts.xml:

   <?xml version="1.0" encoding="UTF-8"?>
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello" class="com.tutoriaspoint.struts2.HelloWordAction"
        method="execute">
<result name="success">HelloWord.jsp</result>
</action>       
</package>
</struts>

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">

   <display-name>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   <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>
</web-app>

My action class:

package com.tutoriaspoint.struts2;


public class HelloWordAction    {


    private String name;

    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
        }
    public String execute() throws Exception {
        return "succes";
        }
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • You've mapped `success`, but returning `succes`. Also consider replacing all the [`Word`s with `World`s](https://it.wikipedia.org/wiki/Hello_world), for the sake of the Information Technology :) – Andrea Ligios Feb 07 '16 at 22:58
  • I changed result name in "ok", ma the error is alway the same. Sorry for world, I' don't know why I always omit the 'L' :) – Sara Maffettone Feb 08 '16 at 07:03
  • Add action extension, like hello.action – Andrea Ligios Feb 08 '16 at 08:48
  • @SaraMaffettone create a folder by name Resource in src and place your struts.xml there and try, what are the jars you have added ?? – goodyzain Feb 08 '16 at 12:09
  • @goodyzain ok, (If I create a folder under src, it can be only a root folder, so Eclipse creates Resource under Java Resource and not under src). However, I tried in this way and unfortunatly the error was the same. Jars for WebApp are: commons-fileupload-1.3.1.jar commons-io-2.2.jar commons-lang-2.4.jar commons-lang3-3.2.jar commons-logging-1.1.3.jar commons-logging-api-1.1.jar freemarker-2.3.22.jar javassist-3.11.0.GA.jar ognl-3.0.6.jar struts2-core-2.3.24.1.jar xwork-core-2.3.24.1.jar – Sara Maffettone Feb 08 '16 at 18:42
  • @AndreaLigios where do I exactly add extension .action? – Sara Maffettone Feb 08 '16 at 18:43
  • 1
    @SaraMaffettone In the URL. Not sure what you mean by you can't add a folder under `src`, the point is that `struts.xml` is expected to be at the root of the classpath after deployment. It's a lot easier to use Maven to handle dependencies and the project file structure. – Dave Newton Feb 08 '16 at 21:18
  • @SaraMaffettone In the tutorial you were said to create `classes` folder, not the `class folder`. – Roman C Feb 09 '16 at 18:23
  • Yes, I've seen and I changed, but it's always the same – Sara Maffettone Feb 09 '16 at 20:09
  • I solved with putting struts.xml directly under src, and writing "/HelloWord "as resulting jsp. Thanks to all! – Sara Maffettone Feb 10 '16 at 18:18

1 Answers1

-1

Just change the struts.xml from name="helloworld" to name="default" and add namespace="/"

or you can use the below one.

<?xml version="1.0" encoding="UTF-8"?>
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello" class="com.tutoriaspoint.struts2.HelloWordAction"
        method="execute">
<result name="success">HelloWord.jsp</result>
</action>       
</package>
</struts>
Bhaskara Arani
  • 1,556
  • 1
  • 26
  • 44