eclipse Struts2 Web 应用程序中的 HTTP 状态 404
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25434855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP Status 404 in Struts2 web application
提问by BustedSanta
Here is my set up:
这是我的设置:
Specs:
眼镜:
- Tomcat 7.0.55
- jdk1.8.0_11
- Eclipse Luna
- Win 8.1
- 雄猫 7.0.55
- jdk1.8.0_11
- 月蚀月神
- 赢8.1
I have a Dynamic Web Project set up in Eclipse titled "Struts2Test" with following structure. Note: I am highlighting only the folders and files relevant to this question.
我在 Eclipse 中设置了一个名为“Struts2Test”的动态 Web 项目,其结构如下。注意:我仅突出显示与此问题相关的文件夹和文件。
Struts2Test (project name)
- [Java Resources]
- [src]
- [com.struts2action] (package)
- HelloWorldAction.java
- [Libraries]
- [Struts2] (user defined library)
- antlr-2.7.2.jar
- bsf-2.3.0.jar
- commons-beanutils-1.8.0.jar
- commons-chain-1.2.jar
- commons-digester-1.8.jar
- commons-fileupload-1.1.1.jar
- commons-io-1.1.jar
- commons-logging-1.0.4.jar
- commons-validator-1.3.1.jar
- jstl-1.0.2.jar
- oro-2.0.8.jar
- standard-1.0.6.jar
- struts-core-1.3.10.jar
- struts-el-1.3.10.jar
- struts-extras-1.3.10.jar
- struts-faces-1.3.10.jar
- struts-mailreader-dao-1.3.10.jar
- struts-scripting-1.3.10.jar
- struts-taglib-1.3.10.jar
- struts-tiles-1.3.10.jar
- [Web Content]
- [WEB-INF]
- [classes]
- struts.xml
- web.xml
- error.jsp
- index.jsp
- success.jsp
web.xml
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml
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>
<package name="helloworld" extends="struts-default">
<!-- URL: hello -->
<action name="hello"
class="com.struts2action.HelloWorldAction"
method="execute">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- more actions can be listed here -->
</package>
<!-- more packages can be listed here -->
</struts>
HelloWorldAction.java
HelloWorldAction.java
package com.struts2action;
public class HelloWorldAction {
public String execute() {
System.out.println("HelloWorldAction - called");
return "success";
}
}
I run and compile the program. I call the following:
我运行并编译程序。我称之为:
http://localhost:8085/Struts2Test/hello.action
I keep getting the following error:
我不断收到以下错误:
HTTP Status 404 - /Struts2Test/hello.action
HTTP 状态 404 - /Struts2Test/hello.action
type Status report message /Struts2Test/hello.action description The requested resource is not available.
type 状态报告消息 /Struts2Test/hello.action description 请求的资源不可用。
Apache Tomcat/7.0.55
Apache Tomcat/7.0.55
Could anyone please advise what the issue with my configuration is?
任何人都可以请告知我的配置有什么问题吗?
采纳答案by BustedSanta
I've resolved my issue by removing the user-defined library and I added the jars directly to WEB-INF/classes folder. Please, note that the jars on the picture are different from the jars listed in my question. I am only starting to learn about Struts2 so I am not even sure whether I need all those jars in there. Either way, thanks you all for your help and feedback.
我通过删除用户定义的库解决了我的问题,并将 jars 直接添加到 WEB-INF/classes 文件夹。请注意,图片上的罐子与我的问题中列出的罐子不同。我才刚刚开始学习 Struts2,所以我什至不确定我是否需要在那里安装所有这些 jar。无论哪种方式,感谢大家的帮助和反馈。
回答by Naveen Kumar
I tried the same code on Apache Tomcat 6.0 and It is working fine there.
我在 Apache Tomcat 6.0 上尝试了相同的代码,并且在那里运行良好。
On Tomcat7 you may need to use Struts2 Prepare and Execute Filter.
在 Tomcat7 上,您可能需要使用 Struts2 准备和执行过滤器。
Try with replacing your filter code with following as Filter Dispatcher is97 deprecated now.
尝试使用以下内容替换过滤器代码,因为现在不推荐使用 Filter Dispatcher is97。
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
Just one more question, are you able to see your System out statement on console?
还有一个问题,你能在控制台上看到你的 System out 语句吗?
回答by Pawan
Try keeping the jar files inside /WEB-INF/lib
尝试将 jar 文件保存在 /WEB-INF/lib 中