导航

Spring MVC 原生API

Posted on 2017-09-27 21:13  耍流氓的兔兔  阅读(272)  评论(0编辑  收藏  举报

 

原生API:

  Servlet环境中一些有用的对象:

    HttpServletRequest
    HttpServletResponse
    HttpSession
    Reader
    Writer
    InputStream
    OutputStream
    java.security.Principal
 

1 配置环境

  1.1 添加servlet运行环境:

  1.2 引入pom坐标

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

2 使用原生API

  直接在controller层的方法的参数列表中添加需要的对象即可
    @RequestMapping("/index")
    public String home(HttpSession session) {
        
        System.out.println(session.getId());
return "home"; }