Abhijeet Panwar
Abhijeet Panwar

Reputation: 1867

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 :

enter image description here

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.

Upvotes: 1

Views: 461

Answers (1)

Andrea Ligios
Andrea Ligios

Reputation: 50203

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.

Upvotes: 1

Related Questions