Eclipse中的Tomcat - HTTP状态404请求的资源不可用

时间:2016-05-11 09:53:35

标签: java xml eclipse tomcat

我快要忘记了。

我按照这里的教程

Java servlet tutorial for beginners

我有这个index.html文件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

web.xml文件

enter image description here

两个文件都在WebContent文件夹中

我可以毫无问题地运行Tomcat并且

http://localhost:8080/

工作正常,但是当我运行应用程序或转到

http://localhost:8080/ServletTutorial/ 

http://localhost:8080/ServletTutorial/index.html

它给出404错误请求的资源不可用。

我已经将Tomcat配置为使用Tomcat安装。

我快要哭了......我已经被困在这里两天了:(

mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server version:        Apache Tomcat/8.0.33
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server built:          Mar 18 2016 20:31:49 UTC
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server number:         8.0.33.0
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Name:               Windows 10
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Version:            10.0
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Architecture:          x86
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Java Home:             C:\Program Files (x86)\Java\jre1.8.0_91
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Version:           1.8.0_91-b14
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Vendor:            Oracle Corporation
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_BASE:         C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_HOME:         C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.base=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.home=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dwtp.deploy=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\wtpwebapps
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Djava.endorsed.dirs=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\endorsed
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dfile.encoding=Cp1252
mag 11, 2016 11:57:21 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAZIONI: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre1.8.0_91\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files (x86)/Java/jre1.8.0_91/bin/client;C:/Program Files (x86)/Java/jre1.8.0_91/bin;C:/Program Files (x86)/Java/jre1.8.0_91/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Antonio\Desktop\eclipse;;.
mag 11, 2016 11:57:21 AM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["http-nio-8080"]
mag 11, 2016 11:57:21 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAZIONI: Using a shared selector for servlet write/read
mag 11, 2016 11:57:21 AM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["ajp-nio-8009"]
mag 11, 2016 11:57:21 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAZIONI: Using a shared selector for servlet write/read
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.Catalina load
INFORMAZIONI: Initialization processed in 1246 ms
mag 11, 2016 11:57:21 AM org.apache.catalina.core.StandardService startInternal
INFORMAZIONI: Starting service Catalina
mag 11, 2016 11:57:21 AM org.apache.catalina.core.StandardEngine startInternal
INFORMAZIONI: Starting Servlet Engine: Apache Tomcat/8.0.33
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\docs
mag 11, 2016 11:57:22 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFORMAZIONI: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [224] milliseconds.
mag 11, 2016 11:57:22 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\docs has finished in 730 ms
mag 11, 2016 11:57:22 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\examples
mag 11, 2016 11:57:23 AM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: ContextListener: contextInitialized()
mag 11, 2016 11:57:23 AM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: SessionListener: contextInitialized()
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\examples has finished in 857 ms
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\host-manager
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\host-manager has finished in 57 ms
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\manager
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\manager has finished in 62 ms
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT has finished in 31 ms
mag 11, 2016 11:57:23 AM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["http-nio-8080"]
mag 11, 2016 11:57:23 AM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["ajp-nio-8009"]
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.Catalina start
INFORMAZIONI: Server startup in 1834 ms

2 个答案:

答案 0 :(得分:1)

您的应用未部署到Tomcat,因为没有日志记录,例如

Deployment of web application directory ... ServletTutorial

当你配置eclipse使用tomcat安装时,尝试检查tomcat的webapp文件夹 - 应该有你的app文件的ServletTutorial目录。根据教程检查其完整性。如果不存在,请删除应用程序并再次添加,或使用“服务器”窗口中的“清洁”菜单选项进行完全重新发布。

我建议不要乱用tomcat安装目录,但将其配置为使用工作空间元数据文件夹。然后,只有您的应用程序将与经理,示例和其他不必要的应用程序一起启动,从而减少您的开发周期时间。

答案 1 :(得分:0)

如今(java ee 2019-09),web.xml文件位于Tomcat文件夹中,检查其默认是否具有相同的文件名:

like this