There is no Action mapped for namespace / and action name hello

那年仲夏 提交于 2019-12-06 06:14:51
  1. Use the new filter

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    

    instead of the old one

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    

    unless you are using a very old version of Struts2 (2.0 for example).

  2. Your web.xml deployment descriptor is messed up: you are saying it is 3.0, then linking 2.5 xmlns:web.

    If you have a Servlet 3.0 Container (Java EE 6) use:

    <web-app          xmlns="http://java.sun.com/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
                    version="3.0">
    

    If you have a Servlet 2.5 Container (Java EE 5) use:

    <web-app          xmlns="http://java.sun.com/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                    version="2.5">
    
  3. Specify namespace in your package declaration, so when you will add new packages you won't have problems:

    <package name="helloworld" extends="struts-default" namespace="/" >
    
  4. No need to specify the method in Action config if it is execute(), and no need to specify the result if it is "success":

    <action name="hello" class="com.tutorialspoint.struts2.HelloWorldAction" >
        <result>/HelloWorld.jsp</result>
    </action>
    
  5. Better using HTML5 DOCTYPE and UTF-8 CharSet if possible.

In your Struts.xml you have given

<package name="helloworld" extends="struts-default"> Try after changing it to

<package name="default" extends="struts-default">

I Hope this answer solves the problem ...

Clean your application directory but most importantly i see that you are missing the namespace.

Sample package entry is enter code here

The package name is a logical name that you give , but the namespace needs to be "/" or if there is any other context then that name

Ryan

To anyone still experiencing these issues, please take a look at my answer on here.

This helped me after struggling for nearly an hour. I followed tutorials step-by-step and still got the error.

Let me know if it helped. Happy coding :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!