当前位置: 代码迷 >> J2EE >> Spring MVC HTTP ERROR 404,该怎么处理
  详细解决方案

Spring MVC HTTP ERROR 404,该怎么处理

热度:73   发布时间:2016-04-22 01:19:57.0
Spring MVC HTTP ERROR 404
在学习Spring mvc 的时候遇到这个问题:

请求能够到达Controller,但是Controller在return的时候, 找不到对应的视图文件, 报错

HTTP ERROR 404

Problem accessing /views/index.jsp. Reason:

  NOT_FOUND

但是当我不配置Spring MVC 的时候 用localhost:8888/views/index.jsp 是可以打开这个页面的。

请各位不舍赐教。

web.xml 代码:

XML code
<?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"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">        <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath*:/spring/*.xml</param-value>    </context-param>    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>        <listener>        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>    </listener>        <servlet>        <servlet-name>spring</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <load-on-startup>1</load-on-startup>        <init-param>            <description>加载/WEB-INF/目录下的所有XML作为Spring MVC的配置文件</description>            <param-name>contextConfigLocation</param-name>            <param-value>/WEB-INF/spring/spring-servlet.xml</param-value>        </init-param>    </servlet>        <servlet-mapping>        <servlet-name>spring</servlet-name>        <url-pattern>/*</url-pattern>    </servlet-mapping>         <filter>        <filter-name>encoding-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>        <init-param>            <param-name>forceEncoding</param-name>            <param-value>true</param-value>        </init-param>    </filter>    <filter-mapping>        <filter-name>encoding-filter</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>            <welcome-file-list>        <welcome-file>index.html</welcome-file>    </welcome-file-list></web-app>


dispatcher-servlet.xml 代码:
XML code
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:p="http://www.springframework.org/schema/p"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:oxm="http://www.springframework.org/schema/oxm"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd                                          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd                                          http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">    <!-- SpringMVC相关Bean配置 -->         <context:component-scan base-package="com.gae.controllers" />            <!-- View Resolver -->     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />         <property name="prefix" value="/views/" />         <property name="suffix" value=".jsp" />     </bean>     <bean id="viewNameTranslator"     class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/>     <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>     </beans>
  相关解决方案