1

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Abhijeet Panwar
  • 1,837
  • 3
  • 26
  • 48

1 Answers1

1

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.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • @AbhijeetPanwar It's not a matter of trying, that was a problem and this is the solution: never put `struts.xml` in `WEB-INF` anymore, because it's wrong. That said, if it still doesn't work, it only means you also have *other* problems. I'm not sure how you ended up like this since you are using Maven! Just run a [Maven Archetype for Struts2](https://struts.apache.org/docs/struts-2-maven-archetypes.html) (like the **Blank** or **Blank Convention**) and take a look at the differences between its structure and your project structure (and/or just drop your and use the archetype one). – Andrea Ligios Oct 28 '15 at 13:01