Tomcat-找不到404页面问题

时间:2019-02-27 01:29:38

标签: java eclipse tomcat9

当我使用eclipse启动tomcat 9,然后导航到http://localhost:8080时,它会显示404-未找到页面并引发错误:“原始服务器未找到目标资源的当前表示或不愿意披露存在”。但是,当我转到tomcat目录并使用tomcat9w.exe启动该过程,然后执行http://localhost:8080时,页面显示完美。可能是什么问题?

Elipse tomcat startup logs:

Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name:   Apache Tomcat/9.0.16
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Feb 4 2019 16:30:29 UTC
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.16.0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_201
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_201-b09
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\Users\vijay\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\vijay\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\vijay\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 9.0\endorsed
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.6.5].
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized [OpenSSL 1.1.1a  20 Nov 2018]
Feb 26, 2019 7:24:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Feb 26, 2019 7:24:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Feb 26, 2019 7:24:14 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [697] milliseconds
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Feb 26, 2019 7:24:14 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.16]
Feb 26, 2019 7:24:15 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Feb 26, 2019 7:24:15 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Feb 26, 2019 7:24:15 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [388] milliseconds

I see the tomcat server in eclipse is started without any problem but can not reach to default website..

THanks

2 个答案:

答案 0 :(得分:0)

  1. 您的“ HTTP 404:未找到文件”可能意味着您在Eclipse项目中缺少“ index.jsp”。

  2. 从Eclipse运行Tomcat与从命令提示符运行tomcat(或等效地,作为Windows服务)相同。

    即使您指向 SAME Tomcat安装(Eclipse> Services> Add),Eclipse也会从不同子文件夹“ tomcat9w.exe”执行。

    您可以在发布的日志中看到此内容:C:\Users\vijay\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core。尝试从两种方式开始,并比较“ CATALINA_BASE”。


感谢您提供其他信息。具体来说:

  1. 问:这是从成功启动Tomcat开始的,对吗?大概是从运行tomcat9w.exe开始的吗?

    [26/Feb/2019:17:27:56 -0600] "GET / HTTP/1.1" 200 11488 0:0:0:0:0:0:0:1 - - 
    [26/Feb/2019:17:27:56 -0600] "GET /tomcat.png HTTP/1.1" 200 5103 Eclipse Catina Logs for tomcat: 127.0.0.1 - - 
    
    [26/Feb/2019:19:13:38 -0600] "GET / HTTP/1.1" 404 1074 0:0:0:0:0:0:0:1 - - 
    [26/Feb/2019:19:13:43 -0600] "GET / HTTP/1.1" 404 1074 0:0:0:0:0:0:0:1 - - 
    [26/Feb/2019:19:13:57 -0600] "GET / HTTP/1.1" 404 1074 0:0:0:0:0:0:0:1 - - 
    
  2. 问:这是与从Eclipse运行Tomcat完全不同的日志消息集,对吗?

  3. 除非Tomcat“无法找到”所请求的资源,否则您将不会获取HTTP 404。在此,该资源为“ /”。这意味着它希望找到一个“索引文件”,例如“ index.html”,“ index.jsp”或等效文件。

  4. 对于Eclipse项目,这意味着在“ webapp”文件夹的根目录中有一个“ index.jsp”。

  5. 问题:

    问:以上陈述1)和2)是否正确?

    问:您的“ tomcat9w.exe”启动程序是否打印CATALINA_BASE和端口号?如果是,请将其复制/粘贴到您的原始帖子中。

    问:您的Eclipse日志是否打印任何错误消息?如果是这样,请将其复制/粘贴到您的原始帖子中。

    问:您是否有“ index.jsp”?它在Eclipse项目中的什么位置?直接在“ webapp”下?您还在“ C:\ Users \ vijay \ eclipse-workspace.metadata.plugins \ org.eclipse.wst.server.core”下的任何位置看到它吗?进入Windows资源管理器并查看。

请发回找到的内容。

答案 1 :(得分:0)

测试项目以在Eclipse中启动的方法是右键单击项目,然后单击 运行方式>在服务器上运行

如果这项工作有效,那么您的tomcat最初并没有指向该项目。因此无法找到index.jsp / html。

如果您没有项目,并且想从eclipse中启动tomcat并显示默认的tomcat主页,则可以执行此操作。

双击“服务器”下的“ Tomcat服务器”,然后从该选项中选择它。 Use Tomcat Installation

现在应该可以了。