0 0

No mapping found for HTTP request with URI [/] in DispatcherServlet with name5

  最近这几天我在配置springMVC项目的时候遇到了一个问题,在网上也找了一下试过了,但是还是不能够解决。
  主要是我配置好了之后我访问首页,在console端缺No mapping found for HTTP request with URI [/] in DispatcherServlet with name,始终没有找到原因,请大家帮我看一下我哪里是不是配置有问题呀:
  web.xml
 
     <servlet>
    <servlet-name>taoziShop</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:taoziShop-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>taoziShop</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  

,然后我再src下面写了一个配置文件如下:
  taoziShoop-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:context="http://www.springframework.org/schema/context"  
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
           http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
            http://www.springframework.org/schema/context  
           http://www.springframework.org/schema/context/spring-context-3.2.xsd  
           http://www.springframework.org/schema/aop  
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd  
           http://www.springframework.org/schema/tx   
           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
           http://www.springframework.org/schema/mvc   
           http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">   
	<!-- 向spring中注入默认注解映射处理器以及把指定控制包下面的控制层注入到spring中 -->
	<mvc:annotation-driven />
	<mvc:default-servlet-handler/>
	<context:annotation-config/>
	<context:component-scan base-package="com.taoziShop.ebiz">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
	</context:component-scan>
	
	<mvc:resources location="/static/js" mapping="/js/**"/>
	<mvc:resources location="/static/images" mapping="/images/**"/>
	<mvc:resources location="/static/css" mapping="/css/**"/> 
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
	    <property name="prefix" value="/WEB-INF/view/"></property>
	    <property name="suffix" value=".jsp"></property>
	</bean>
</beans>

我的控制器是这么写的:
    package com.taoziShop.ebiz.action;

import java.util.ArrayList;
import java.util.List;

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

@Controller
public class IndexController {

	@RequestMapping(value={"/","/index.do"})
	public String toHomePage(ModelMap modelMap) throws Exception {
		List<Integer> numList = new ArrayList<Integer>();
		for (int index = 0; index <= 10; index++) {
			numList.add(index);
		}
		
		modelMap.addAttribute("numList", numList);
		return "index";
	}
}
,希望大家帮我看看就是出现什么问题,每次访问首页好像找不到相应的控制层。
2014年8月19日 01:31

1个答案 按时间排序 按投票排序

0 0

有几个地方不对:
1、web.xml中的<url-pattern>/</url-pattern>改为<url-pattern>/*</url-pattern>

2、taoziShoop-servlet.xml 和 <param-value>classpath*:taoziShop-servlet.xml</param-value>里面的不一致。

2014年8月19日 15:03

相关推荐

Global site tag (gtag.js) - Google Analytics