简体   繁体   中英

No action mapped for namespace [/] and action name

I have just started with Struts2 framework . So I am just trying to create a basic program .

Code in web.xml:

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

Code for Struts.xml File:

<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

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

       <action name="gettutorial"  class="com.abhijeet.actions.TutorialAction"  method="execute">
           <result name="success">result.jsp</result>
       </action>     
   </package>

</struts>

Action class code:

package com.abhijeet.actions;

import com.opensymphony.xwork2.ActionSupport;


public class TutorialAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    @Override
    public String execute()
    {
      System.out.println("Execute method is called");
      return "success";
    }
}

My Project structure is like :

在此处输入图片说明

When I run http://localhost:8080/Struts2check/gettutorial.action url it displays error message :

"There is no Action mapped for namespace [/] and action name [gettutorial] associated with context path [/Struts2check]. - [unknown location]".

I am not able to find the issue as it seems correct to me. Please let me know if I am missing something or If I have done any mistake.

The struts.xml configuration file must be put on the classpath root,

hence on /WEB-INF/classes , and not just /WEB-INF .

The rest of your configuration seems fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM