Java 无动作映射-Struts 2

Java 无动作映射-Struts 2,java,maven,struts2,action-mapping,Java,Maven,Struts2,Action Mapping,下午好 我意识到这个问题已经被问了很多次了,但是这些问题主要是由将struts.xml文件放在错误的位置或者拼写错误路径名或其他东西引起的 我已尽可能地遵循Struts 2网站上的教程,但不断出现以下错误: HTTP Status 404 - There is no Action mapped for namespace [/] and action name [hello] associated with context path [/basic_struts]. 我选择Maven作为构建

下午好

我意识到这个问题已经被问了很多次了,但是这些问题主要是由将
struts.xml
文件放在错误的位置或者拼写错误路径名或其他东西引起的

我已尽可能地遵循Struts 2网站上的教程,但不断出现以下错误:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [hello] associated with context path [/basic_struts].
  • 我选择Maven作为构建工具
  • 我的
    struts.xml
    文件位于
    WebContent
    文件夹的根目录中,而不是
    WEB-INF\classes
    文件夹中的文件
下面是我的
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="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>
问题

1) 我放置的
struts.xml
文件是否正确?(注意-我的
web.xml
文件位于
web-INF
文件夹中),如果不是,应该放在哪里

(注意-我读到它应该放在
src/main/resources
文件夹中,但它在哪里?我本以为它是java资源的一部分,但为什么要放在那里?)

2) 您是否需要在lib文件夹或构建路径中包含任何jar才能工作?从网站上,您所要做的就是在Maven pom文件中包含一个依赖项-在我的文件中,看起来如下所示:

<p>
    <a href="<s:url action='hello'/>">Hello World</a>
</p>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.16</version>
    </dependency>

org.apache.struts

这有一个很好的屏幕截图,显示了struts文件的位置-请记住将其命名为struts.xml(小写),而不是大写。

看起来像是错误的简要说明:
struts.xml
文件应该位于web应用程序类路径上
src/main/resources
对应于Maven项目结构,应该作为源文件夹添加到web项目中。构建时,它将与编译的其他源文件夹合并,并与编译的类一起放置到编译器输出的文件夹中。部署时,将编译器输出文件夹复制到
WEB-INF/classes
。看

那么,我对struts文件的定位是否正确,还是需要移动它?@Katana24。。。您的
struts.xml
位于WEB-INF中。WEB-INF不在类路径上。显然,您需要移动它,以遵循文档和其他S2关于放置错误的
struts.xml
的回答。还有您正在学习的教程。@Katana24将其移动到
src/main/resources
src/main/java
@romac i know-我用答案更新了我的问题,并链接到了我找到答案的地方answer@Katana24如果与问题答案相关的这个和那个对你有帮助,那么你应该接受并投票表决。