当前位置: 代码迷 >> Java Web开发 >> Spring MVC 404异常
  详细解决方案

Spring MVC 404异常

热度:935   发布时间:2016-04-16 22:16:39.0
Spring MVC 404错误
错误提示:
message /springMVC/WEB-INF/jsp/hello.jsp
description The requested resource is not available.


web.xml
	<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 
<init-param>  
<param-name>contextConfigLocation</param-name>  
<param-value>/WEB-INF/hello-servlet.xml</param-value> 
</init-param> 
 -->
<load-on-startup>1</load-on-startup>

</servlet>

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

spring-servlet.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
     http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.hwr.controller"/>
    <mvc:annotation-driven />
  
    <!--
    <bean id="viewResolver"
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"
     p:prefix="/WEB-INF/jsp/"
     p:suffix=".jsp"/>-->
</beans>

HelloController.java
package com.hwr.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;



@Controller
public class HelloController {

@RequestMapping(value="/")
public String returnMess(){
System.out.println("hello");
return "/WEB-INF/jsp/hello.jsp";
// return new ModelAndView("hello");
// return "hello";
}
}

hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>hello!!!</h1>
</body>
</html>


项目结构:
-WebContent
    +META-INF
    -WEB-INF
        -jsp
            hello.jsp
        +lib
        spring-servlet.xml
        web.xml


url访问:(ps:端口被修改成了91)
http://localhost:91/springMVC/


疑惑:
    访问时,页面显示HTTP Status 404的错误,以及以下信息,弄了很久也找不出原因,求大牛指点!
type Status report
message /springMVC/WEB-INF/jsp/hello.jsp
description The requested resource is not available.





------解决方案--------------------
引用:
Quote: 引用:

把 return "/WEB-INF/jsp/hello.jsp" 改成return "WEB-INF/jsp/hello.jsp" 去掉/试试

试过了,也是不可以
 我本地试过了,是可以的,你该把项目启动报的错贴出来
------解决方案--------------------
WEB-INF目录下的资源不能直接访问,除非你有静态资源访问的配置
------解决方案--------------------
你这问题肯定是哪里犯了什么低级错误,你把项目上传一下吧,配个spring MVC应该很简单才对
  相关解决方案