SpringMVC获取servlet原生API

先设置一个链接跳到controller。

 

在servletAPI方法中添加HttpServletRequest request , HttpServletResponse response 两个参数

  @RequestMapping(path="/servletAPI")
    public String servletAPI(HttpServletRequest request , HttpServletResponse response){

        HttpSession session = request.getSession();
        System.out.println(session);

        ServletContext servletContext = session.getServletContext();
        System.out.println(servletContext);

        System.out.println(request);
        System.out.println(response);

        return "success";
    }

页面跳转后控制台就会打印

你可能感兴趣的:(SpringMVC)