Java web项目报错:HTTP Status 404 – Not Found Type Status Report Message /WebProject/ Description The ori

时间:2024-04-01 11:56:44

在用intelijIDEA的时候,因为是第一次接触这个,对项目的发布很是迷糊。怎么弄老是404错误:

HTTP Status 404 – Not Found


Type Status Report

Message/****

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

无奈之下,换成eclipse,发现问题也是存在。捣鼓了好几天,都不知道问题出在哪里。后来打算新建一个Web项目,新建一个index.jsp正确运行后再慢慢复制以前的项目文件到该正确web下面,看看问题出在哪里。后来终于发现了,使用新建的web项目下的默认web.xml文件时,项目正确运行:

Java web项目报错:HTTP Status 404 – Not Found Type Status Report Message /WebProject/ Description The ori

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>WebProject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

我原来的报错项目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">
  <filter>
    <filter-name>spring filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>spring filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>ServletProxyService</servlet-name>
    <servlet-class>com.proxy.ServletProxyService</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>ServletProxyService</servlet-name>
    <url-pattern>/ServletProxyService</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/error.html</location>
  </error-page>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

使用这个web.xml项目就无法运行:

Java web项目报错:HTTP Status 404 – Not Found Type Status Report Message /WebProject/ Description The ori

web.xml换成自动生成的就可以运行了。具体原报错项目web.xml哪里错了,应该是springmvc相关配置出错吧!

就在刚刚:2018-7-29 12点18分

我把web.xml最后几段删除:

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

发现项目正确运行,所以就是这个spring的配置有问题。

https://blog.csdn.net/zuoyexingchennn/article/details/50426869#commentBox

这个链接完美解决了我的问题:

就是将注释里的代码改为这个:

 <!-- 
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>  
-->
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
    </context-param>