zoukankan      html  css  js  c++  java
  • springmvc 获取request response

    RequestContextHolder 获取request

    public HttpServletRequest getRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
    1
    2
    3
    public ServletContext getServletContext() {
    return ContextLoader.getCurrentWebApplicationContext().getServletContext();
    }
    1
    2
    3
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){
    this.request = request;
    this.response = response;
    this.session = request.getSession();
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    写入参数的就不多说了

    @RequestMapping("/path")
    public void go(HttpServletRequest req, HttpServletResponse resp){
      
    }
    ---------------------
    作者:xyw10000
    来源:CSDN
    原文:https://blog.csdn.net/xuyw10000/article/details/51673531
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    io学习三
    io学习二
    io学习一
    多线程学习(十五)
    spring源码阅读(四)
    多线程学习(十四)
    多线程学习(十三)
    设计模式(一)
    spring源码阅读(三)
    spring源码阅读(二)
  • 原文地址:https://www.cnblogs.com/Jeely/p/10811846.html
Copyright © 2011-2022 走看看