Struts Hello world example : There is no Action mapped for namespace [/] and action name error
Asked Answered
B

7

11

i am absolute beginner to Struts2. I am tying to follow tutorials on struts web site. i followed this tutorial. i have some trouble with it. i created dynamic web project on eclipse. Then i followed the tutorial. However when i run the example i get the following error.

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

i have the following directory structure

enter image description here

And my struts.xml file is

 <?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="basicstruts2" extends="struts-default" namespace="/">

  <action name="index">
    <result>/index.jsp</result>
  </action>

  <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
    <result name="SUCCESS">/HelloWorld.jsp</result>
  </action>

</package>

</struts>

thanks for your responses.

Breadstuff answered 24/1, 2012 at 17:50 Comment(1)
i tried to put it inside code block but i could not make it. Now, it is ok, i think.Breadstuff
J
18

The struts.xml configuration file needs to be on the classpath (as opposed to in WEB-INF).

The linked tutorial assumes a Maven build and states the struts.xml file should go in src/main/resources, which will be included in the classpath in Maven builds. Since you're ignoring that part, you'll likely want to put it in the root of your source directory.

Jp answered 24/1, 2012 at 18:11 Comment(2)
thanks a lot. this solved the problem. However, i get another error "no result defined for action and result success" any idea ?Breadstuff
@Breadstuff Yep; your result's name is "SUCCESS", but Action.SUCCESS is the string "success" (lowercase). That's a guess, since I don't know what your action looks like. Also, "execute" is the default method and doesn't need to be specified. (And "success" is the default result name if you don't want to explicitly define it.)Jp
I
3

You have to create a classes/ folder under WEB-INF/ and put in your struts.xml file!

Iona answered 23/9, 2012 at 22:17 Comment(0)
S
2

Right click the project. Go to properties deployment build path and add all .jar files to /WEB-INF/lib.
Then you shouldn't get this error.

struts.xml should be located under directory: src/struts.xml..

And WEB-INF/web.xml you we need to configure the struts based on filter..

Skedaddle answered 25/4, 2013 at 8:30 Comment(0)
C
1

I got the same error and got solution looking at tomcat log when restarting : doctype were missing in struts.xml

so I added

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

now it works !

Christenachristendom answered 11/6, 2013 at 10:25 Comment(0)
B
1

I solved the issue by adding default-action-ref tag, for example,

<default-action-ref name="home" />

after package tag

in struts.xml

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

<default-action-ref name="upload" />
Bracketing answered 22/9, 2013 at 6:17 Comment(0)
T
0

I had the same issue and I was facing it because of not mentioning the namespace correctly in struts.xml.

I added the following snippet in the web.xml :

<welcome-file>login.jsp</welcome-file>

and also making the namespace as "/" default... Hope it answers your query..

Threap answered 1/10, 2014 at 10:18 Comment(0)
D
-1

In my case I had to rename Struts.xml ---> struts.xml

Daliladalis answered 24/1, 2015 at 21:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.