关闭

No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'

2054人阅读 评论(0) 收藏 举报
分类:

输入http://localhost:8080/index.html,后台一直报这个错:No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'

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>javademo</display-name>
  
   <!--  Spring 服务层的配置文件 -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
       <param-value>classpath:applicationContext.xml</param-value>   
        <!-- <param-value>/WEB-INF/applicationContext*.xml</param-value> -->
    </context-param>  
      
    <!--  Spring 容器启动监听器 -->  
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener  
        </listener-class>  
    </listener>  
  
    <servlet>  
        <servlet-name>springmvc</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet  
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/springmvc-servlet.xml</param-value>
        </init-param> 
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <!--为DispatcherServlet建立映射 -->  
    <servlet-mapping>  
        <servlet-name>springmvc</servlet-name>  
        <url-pattern>*.html</url-pattern> 
        <!--<url-pattern>/*</url-pattern>  --> 
    </servlet-mapping>  
  
  
  
  <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>
查了一下,这个配置文件是没有错的,原因是因为java文件中少了@controller注解;

package com.netease.web.controller;

import java.util.Map;

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


@Controller
public class IndexController {
	
	@RequestMapping("index")
	public String xbsr(){
		return "index";	
	}

}





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:41759次
    • 积分:893
    • 等级:
    • 排名:千里之外
    • 原创:48篇
    • 转载:6篇
    • 译文:0篇
    • 评论:0条
    博客专栏