Tomcat HTTP状态404未找到错误

时间:2016-02-05 10:11:09

标签: java spring tomcat http-status-code-404

当我在Tomcat 7中部署war文件时,我收到404错误页面。我可以在eclipse中从Jetty服务器运行我的应用程序,没有任何问题。我只是进行war导出并在Tomcat 7 webapps文件夹中部署应用程序并使用端口9090启动tomcat服务器,并返回404 not found错误。 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_2_5.xsd" 
     version="2.5">

<display-name>mywebapp - Maven Archetype Created Web Application</display-name>

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/applicationContext.xml</param-value>
</context-param>

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:/log4j.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>mywebappServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/config/springContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mywebappServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error</location>
</error-page>

我的控制器类侦听“/”,“/ login”和“/ index”请求并相应地映射到登录页面和索引页面。

@RequestMapping(value="/", method=RequestMethod.GET)

@RequestMapping(value="/login", method=RequestMethod.GET)

@RequestMapping(value="/index", method=RequestMethod.GET)

以上映射在jetty服务器上运行良好。启动tomcat后,我可以在Webapp Manager页面中看到我的应用程序启动并运行设置为true。当我点击mywebapp时,它会显示404错误。

注意:war文件名和我访问的url都是相同的。我正在访问我的网址的网址是http://localhost:9090/mywebapp,战争文件名是mywebapp.war

这是我的tomcat日志,

2016-02-05 15:37:13 Commons Daemon procrun stderr initialized
Feb 05, 2016 3:37:14 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
Feb 05, 2016 3:37:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9090"]
Feb 05, 2016 3:37:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 05, 2016 3:37:14 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 699 ms
Feb 05, 2016 3:37:14 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 05, 2016 3:37:14 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.50
Feb 05, 2016 3:37:14 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\mywebapp.war
Feb 05, 2016 3:37:25 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [178] milliseconds.
Feb 05, 2016 3:37:26 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\host-manager
Feb 05, 2016 3:37:26 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\manager
Feb 05, 2016 3:37:26 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT
Feb 05, 2016 3:37:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]
Feb 05, 2016 3:37:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 05, 2016 3:37:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12010 ms

当我尝试访问http://localhost:9090/mywebapp url时,我在tomcat-stdout-xx中得到以下内容作为输出,

WARN [http-bio-9090-exec-5] servlet.DispatcherServlet (DispatcherServlet.java:1136) - No mapping found for HTTP request with URI [/mywebapp/] in DispatcherServlet with name 'mywebappServlet'

我的配置有什么问题?

0 个答案:

没有答案