Struts Hello world示例:没有为名称空间[/]和操作名称错误映射的操作 [英] Struts Hello world example : There is no Action mapped for namespace [/] and action name error
问题描述
我绝对是Struts2的初学者.我想遵循struts网站上的教程.我遵循了本教程.我有麻烦.我在Eclipse上创建了动态Web项目.然后我按照教程进行.但是,当我运行示例时,出现以下错误.
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]
我具有以下目录结构
我的struts.xml文件是
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>
感谢您的回复.
推荐答案
struts.xml
配置文件必须位于类路径中(与WEB-INF
中相反).
The struts.xml
configuration file needs to be on the classpath (as opposed to in WEB-INF
).
链接的教程假定使用Maven构建,并指出struts.xml
文件应放入src/main/resources
中,该文件将包含在Maven构建的类路径中.由于您忽略了该部分,因此您可能希望将其放在源目录的根目录中.
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.
这篇关于Struts Hello world示例:没有为名称空间[/]和操作名称错误映射的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!