页面未找到404 Apache Tomcat

时间:2016-02-26 06:56:04

标签: java eclipse apache tomcat servlets

我正在尝试学习使用jersey& amp;创建REST服务器servlet的。 我提到this例子。这是早些时候运行但不再是。之前我习惯导出war文件,然后使用命令行& amp;有效。后来我在eclipse中添加了服务器并开始直接运行,url工作,然后突然停止工作。

我几乎每次都会收到404错误,但昨天我重新启动服务器并改变了一些设置之后,网页又恢复了工作。不知道我做了什么。今天我开了日食,我获得了404收益。

我认为tomcat设置可能存在一些问题。我是servlet和tomcat的新手。

的web.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" 
   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>com.aarfid.restserver</display-name>
   <servlet>
      <servlet-name>Jersey RESTful Application</servlet-name>
      <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.aarfid.restserver</param-value>
         </init-param>
      </servlet>
   <servlet-mapping>
   <servlet-name>Jersey RESTful Application</servlet-name>
      <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>  
</web-app>

项目结构

enter image description here

服务器设置

enter image description here

我已提到

Tomcat 7 keeps giving me a 404. What am I doing wrong?

HTTP Status 404 - The requested resource (/) is not available

修改

同样http://localhost:8080也会出现404错误,而eclipse显示服务器已启动。

编辑2 Tomcat日志

Feb 26, 2016 2:17:33 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:WebProject' did not find a matching property.
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.68
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Feb 8 2016 20:25:54 UTC
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.68.0
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 8.1
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.3
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre7
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.7.0_79-b15
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\RachitaData\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\RachitaData\apache-tomcat-7.0.68-windows-x64\apache-tomcat-7.0.68
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\RachitaData\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\RachitaData\apache-tomcat-7.0.68-windows-x64\apache-tomcat-7.0.68
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\RachitaData\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\RachitaData\apache-tomcat-7.0.68-windows-x64\apache-tomcat-7.0.68\endorsed
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Feb 26, 2016 2:17:33 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: 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\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Java\jdk1.7.0_79\bin;C:\Program Files\Git\cmd;.
Feb 26, 2016 2:17:33 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 26, 2016 2:17:33 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 26, 2016 2:17:33 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 756 ms
Feb 26, 2016 2:17:33 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 26, 2016 2:17:33 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.68
Feb 26, 2016 2:17:33 AM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(C:\RachitaData\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\WebProject\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Feb 26, 2016 2:17:34 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 26, 2016 2:17:34 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 26, 2016 2:17:34 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 26, 2016 2:17:34 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1353 ms

4 个答案:

答案 0 :(得分:0)

试试这个:

<listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.aarfid.restserver</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

如果它不起作用,请在您的问题中添加您使用的库和服务类......

这样的结构:

src
----main
-------java
--------------packages
-------resourses
-------webapp
----------WEB-INF
--------------web.xml

答案 1 :(得分:0)

收到偶数http://localhost:8080的404 检查你的Tomcat。 - 选择了8080端口 - 去安装路径或你的Tomcat - 文件夹'conf'/ File server.xml

那里(第70行)你应该找到一些像

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

检查,那里写的是什么

    Eclipse中的
  • :你如何开始你的项目? - 在您的项目上:'右键上下文菜单' - &gt;运行'在服务器上运行'

答案 2 :(得分:0)

您实际上必须了解服务器上发生了什么以及它是如何工作的。 让我们明确你的信息的一些要点

我正试图学习使用jersey&amp; amp;创建一个REST服务器的servlet。

不是真的,你已经拥有了想要提供休息服务的服务器(你的事业中的tomcat)。

休息服务是特殊形成的http请求的一般概念。

当服务器收到请求时,它会尝试为它找到处理程序。 所有处理程序都在web.xml或Web项目描述符文件中定义。你在web.xml中只有一个处理程序

重要的行是

<servlet-name>Jersey RESTful Application</servlet-name>

<url-pattern>/rest/*</url-pattern>

名为 Jersey RESTful Application 的servlet假设处理哪个url对应于url模式的请求

示例:

good url 
http://localhost:8080/rest/author/34

bad url
http://localhost:8080       not found
http://localhost:8080/author/34          not found
http://localhhost:8080/who-is-that-man      not found

值得一提的另一点是Eclipse Dynamic WebProject默认情况下将WebContext指定为与项目名称相同,除非您明确指定另一个路径(在创建项目期间或您可以在项目设置中更改它)。

这会将好的网址更改为

good url
http://localhost:8080/WebProjectName/rest/author/34

另一个问题可能是服务器的配置被缓存,因为eclipse有Tomcat Catalina服务器的单独文件夹。在这种情况下,它有助于清理tomcat服务器(我认为右键单击服务器,服务器应该停止,选择Clean)或者只是删除并再次创建服务器。

答案 3 :(得分:0)

当我从Eclipse启动servlet以在localhost上的Tomcat上运行时,URL中包含项目名称。假设我的项目名为Foo,index.html的URL将为http://localhost:8080/Foo/index.htmlhttp://localhost:8080/index.html返回404.您是否尝试将项目名称放在网址中?