Struts Hello world示例:没有映射名称空间[/]和操作名称错误的Action

ere*_*can 11 struts2 struts2-namespace action-mapping

我绝对是Struts2的初学者.我想跟随struts网站上的教程.我按照本教程.我有点麻烦.我在eclipse上创建了动态web项目.然后我按照教程.但是,当我运行该示例时,我收到以下错误.

There is no Action mapped for namespace [/] and action name [hello] associated with context path [/Hello_World_Struts_2]. - [unknown location]
Run Code Online (Sandbox Code Playgroud)

我有以下目录结构

在此输入图像描述

我的struts.xml文件是

 <?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>
Run Code Online (Sandbox Code Playgroud)

谢谢你的回复.

Dav*_*ton 17

struts.xml配置文件必须在类路径(而不是在WEB-INF).

链接教程假定Maven构建并声明struts.xml文件应该进入src/main/resources,它将包含在Maven构建的类路径中.由于您忽略了该部分,因此您可能希望将其放在源目录的根目录中.