Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc ContentCachingResponseWrapper:如何使用ContentCachingResponseWrapper获取应用程序响应对象(而不是httpResponse)_Spring Mvc_Httpresponse - Fatal编程技术网

Spring mvc ContentCachingResponseWrapper:如何使用ContentCachingResponseWrapper获取应用程序响应对象(而不是httpResponse)

Spring mvc ContentCachingResponseWrapper:如何使用ContentCachingResponseWrapper获取应用程序响应对象(而不是httpResponse),spring-mvc,httpresponse,Spring Mvc,Httpresponse,在SpringWeb中使用拦截器验证请求。 我已经扩展了HandlerInterceptorAdapter来实现postHandle方法。 我想检查应用程序响应对象中的值,并相应地执行一些操作 我尝试使用IOUtils获取应用程序响应对象,但得到了一个“”字符串 在阅读了许多文档并亲自动手之后,我发现输入流/输出流只能访问一次。响应对象在到达postHandler之前已经在某处写入了输出流。所以输出流在postHandle的响应对象中为空 若要访问postHandle中的响应对象,请使用实际响应

在SpringWeb中使用拦截器验证请求。 我已经扩展了HandlerInterceptorAdapter来实现postHandle方法。 我想检查应用程序响应对象中的值,并相应地执行一些操作

我尝试使用IOUtils获取应用程序响应对象,但得到了一个“”字符串


在阅读了许多文档并亲自动手之后,我发现输入流/输出流只能访问一次。响应对象在到达postHandler之前已经在某处写入了输出流。所以输出流在postHandle的响应对象中为空

若要访问postHandle中的响应对象,请使用实际响应对象设置请求对象的属性

public class XYZInterceptor extends HandlerInterceptorAdapter {

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
        throws Exception {

    ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
    ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);

    // need to retrieve application response object

    return;
  }

}