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 theWebContent
folder and is not in theWEB-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.