分不多,谢谢大家了!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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>spring</display-name>   <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/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>  <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/spring/hello.do</url-pattern>
    </servlet-mapping>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>applicationContext.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"><mvc:annotation-driven/><context:component-scan base-package="java.*"/></beans>index.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="/spring/hello.do">Person List</a>
</body>
</html>hello.javapackage java;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;@Controller
public class hello {
public hello(){

}

@RequestMapping(value = "/spring/hello.do", method = RequestMethod.GET)
public ModelAndView myMethod(HttpServletRequest request, HttpServletResponse response,
             ModelMap modelMap) { 
ModelAndView a = new ModelAndView();
a.addObject("hello.jsp", modelMap);
return a;
}
}我断点打在controller里面,没有跑到
console里面报警告是: No mapping found for HTTP request with URI [/spring/hello.do] in DispatcherServlet with name 'springmvc'
里面哪里有问题,望指正

解决方案 »

  1.   

    <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>/spring/hello.do</url-pattern>
      </servlet-mapping>
    改成
    <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      

  2.   

    给你个参考
    package com.mvc.controller;   
      
    import java.util.List;   
      
    import javax.servlet.http.HttpServletRequest;   
    import javax.servlet.http.HttpServletResponse;   
      
    import org.apache.commons.logging.Log;   
    import org.apache.commons.logging.LogFactory;   
    import org.springframework.beans.factory.annotation.Autowired;   
    import org.springframework.stereotype.Controller;   
    import org.springframework.ui.ModelMap;   
    import org.springframework.web.bind.annotation.RequestMapping;   
    import org.springframework.web.bind.annotation.RequestMethod;   
    import org.springframework.web.bind.annotation.RequestParam;   
    import org.springframework.web.servlet.ModelAndView;   
      
    import com.mvc.entity.Student;   
    import com.mvc.service.StudentService;   
      
    @Controller  
    @RequestMapping("/student.do")   
    public class StudentController {   
        protected final transient Log log = LogFactory   
        .getLog(StudentController.class);   
        @Autowired  
        private StudentService studentService;   
        public StudentController(){   
               
        }   
           
        @RequestMapping  
        public String load(ModelMap modelMap){   
            List<Object> list = studentService.getStudentList();   
            modelMap.put("list", list);   
            return "student";   
        }   
           
        @RequestMapping(params = "method=add")   
        public String add(HttpServletRequest request, ModelMap modelMap) throws Exception{   
            return "student_add";   
        }   
           
        @RequestMapping(params = "method=save")   
        public String save(HttpServletRequest request, ModelMap modelMap){   
            String user = request.getParameter("user");   
            String psw = request.getParameter("psw");   
            Student st = new Student();   
            st.setUser(user);   
            st.setPsw(psw);   
            try{   
                studentService.save(st);   
                modelMap.put("addstate", "添加成功");   
            }   
            catch(Exception e){   
                log.error(e.getMessage());   
                modelMap.put("addstate", "添加失败");   
            }   
               
            return "student_add";   
        }   
           
        @RequestMapping(params = "method=del")   
        public void del(@RequestParam("id") String id, HttpServletResponse response){   
            try{   
                Student st = new Student();   
                st.setId(Integer.valueOf(id));   
                studentService.delete(st);   
                response.getWriter().print("{\"del\":\"true\"}");   
            }   
            catch(Exception e){   
                log.error(e.getMessage());   
                e.printStackTrace();   
            }   
        }   
    }  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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">   
      <display-name>s3h3</display-name>   
       <context-param>     
         <param-name>contextConfigLocation</param-name>     
         <param-value>classpath:applicationContext*.xml</param-value>     
     </context-param>     
      <listener>     
         <listener-class>org.springframework.web.context.ContextLoaderListener</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>     
     </servlet>     
     <servlet-mapping>     
         <servlet-name>spring</servlet-name>  <!-- 这里在配成spring,下边也要写一个名为spring-servlet.xml的文件,主要用来配置它的controller -->   
         <url-pattern>*.do</url-pattern>     
     </servlet-mapping>     
      <welcome-file-list>   
        <welcome-file>index.jsp</welcome-file>   
      </welcome-file-list>   
    </web-app>