Maven-SpringMVC

1.创建maven工程

2.在pom.xml文件中添加依赖项


    4.3.9.RELEASE



    
    
        org.springframework
        spring-webmvc
        ${springframe.version}
    

    
    
        jstl
        jstl
        1.2
    

    
        javax.servlet
        javax.servlet-api
        3.0.1
        
        provided
    

    

    
        com.fasterxml.jackson.core
        jackson-databind
        2.9.1
    



    3.创建文件 spring-mvc.xml
        

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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-4.3.xsd">;







    
    

4.配置web.xml , 加载 spring-mvc.xml
        
    SpringMVC
    org.springframework.web.servlet.DispatcherServlet
    
        contextConfigLocation
        classpath:spring-mvc.xml
    


    SpringMVC
    /




    encodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
        encoding
        UTF-8
    
    
        forceEncoding
        true
    


    encodingFilter
    /*


    5.创建控制层代码 IndexController.java
        @Controller

@RequestMapping("/")
public class IndexController {

    @RequestMapping("index")
    public String index(){
            System.out.println("index");
            return "index";
    }
}
在地址栏输入http://localhost:8080/工程名/index就可访问index.jsp