Struts Hello world example : There is no Action ma

2019-01-24 05:46发布

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.

7条回答
手持菜刀,她持情操
2楼-- · 2019-01-24 06:20

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

查看更多
smile是对你的礼貌
3楼-- · 2019-01-24 06:21

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 !

查看更多
祖国的老花朵
4楼-- · 2019-01-24 06:29

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

查看更多
Viruses.
5楼-- · 2019-01-24 06:31

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

查看更多
Melony?
6楼-- · 2019-01-24 06:32

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" />
查看更多
疯言疯语
7楼-- · 2019-01-24 06:34

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.

查看更多
登录 后发表回答