こんにちは、
この質問が何度も出されていることは承知していますが、これらの質問のほとんどは、struts.xml
ファイルを間違った場所に配置したり、パス名のスペルを間違えたりしたことが原因でした。
Struts 2 Web サイトのチュートリアルにできる限り従いましたが、次のエラーが発生し続けます。
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>
HelloWorld.jsp
また、ファイルをというフォルダーに配置jsp
し、struts ファイルでこれを指摘しました。上記のアクションを呼び出すと想定されるインデックス ファイルのコードは次のようになります。
<p>
<a href="<s:url action='hello'/>">Hello World</a>
</p>
質問
1)struts.xml
ファイルの配置は正しいですか? (注 - 私のweb.xml
ファイルはWEB-INF
フォルダー内にあります)そうでない場合は、どこに配置する必要がありますか?
(注 - フォルダーに配置する必要があると読みましたsrc/main/resources
が、それはどこにありますか?それはJavaリソースの一部だと思っていたでしょうが、なぜそこに配置するのですか?)
2) これを機能させるには、lib フォルダーまたはビルド パスに jar を含める必要がありますか? Web サイトから、Maven pom ファイルに依存関係を含めるだけです。私の場合、これは次のようになります。
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.16</version>
</dependency>
ありがとう
アップデート
Roman C の助けに感謝します。struts ファイルが間違った場所にありました。他の誰かがこの問題を抱えている場合は、struts ファイルを配置する場所の素晴らしいスクリーンショットがあるこの質問をチェックすることをお勧めします-大文字ではなく struts.xml (小文字) と呼ぶことを忘れないでください。