1

Good afternoon,

I realise this question has been asked multiple times but these questions were mostly caused by the person placing the struts.xml file in the incorrect place or mis-spelling a path name or something.

I've followed the tutorial from the Struts 2 website here as best I can but keep getting the following error:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [hello] associated with context path [/basic_struts].
  • I'm using Maven as my build tool of choice
  • My struts.xml file is located in the root of the WebContent folder and is not in the WEB-INF\classes folder.

Below is the structure of my struts.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
        <!-- This minimal Struts 2 configuration file tells the framework that 
            if the URL ends in index.action to redirect the browser to index.jsp. -->
        <action name="index">
            <result>/index.jsp</result>
        </action>

        <action name="hello"
            class="com.me.actions.HelloWorldAction" method="execute">
            <result name="success">jsp/HelloWorld.jsp</result>
        </action>
</package>

I have also placed the HelloWorld.jsp file in a folder called jsp and I've pointed this out in the struts file. The index file code which is suppose to call the above action looks like this:

<p>
    <a href="<s:url action='hello'/>">Hello World</a>
</p>

Questions

1) Is my placing of the struts.xml file correct? (note - my web.xml file is inside the WEB-INF folder) and if not where should it be placed?

(note - i read it should be placed in the src/main/resources folder but where is that? I would have thought that was part of the java resources but why place it there? )

2) Do you need to include any jars in the lib folder or build path for this to work? From the website all you have to do is include a dependency in the Maven pom file - in mine this looks like this:

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.16</version>
    </dependency>

Thanks

Update

Thanks to Roman C for his help. My struts file was in the wrong place. If anyone else has this problem I would recommend checking out this question that has a nice screenshot of where to position the struts file - please remember to call it struts.xml (lowercase) instead of uppercase.

Community
  • 1
  • 1
Katana24
  • 8,706
  • 19
  • 76
  • 118

1 Answers1

1

Looks like a brief explanation of error: the struts.xml file should be on web application classpath. src/main/resources correspond to the Maven project structure and should be added as a source folder to your web project. When built it's merged with other source folders that are compiled and placed to the folder of the compiler output along with compiled classes. When deployed the compiler output folder copied to WEB-INF/classes. See the Maven site for getting started with web projects.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • so am i correct in my positioning of the struts file or do i need to move it? – Katana24 May 07 '14 at 18:28
  • @Katana24 ... Your `struts.xml` is in WEB-INF. WEB-INF is not on the classpath. Obviously you need to move it, to follow what the docs and every other S2 answer regarding a misplaced `struts.xml` says. And the tutorial you're following. – Dave Newton May 07 '14 at 22:52
  • @Katana24 Move it to `src/main/resources` or `src/main/java`. – Roman C May 08 '14 at 08:53
  • @RomanC i know - i updated my question with the answer and link to where I found the answer – Katana24 May 08 '14 at 08:57
  • @Katana24 If this and that linked to the question answer helped you, then you should accept and upvote them. – Roman C May 08 '14 at 09:13