“HttpServletResponse is commited”是什么意思?
2022-09-04 20:36:52
正如标题中所述,HttpServletResponse被提交是什么意思?
我有一些请求拦截器,扩展,覆盖方法。后处理方法采用参数 。在方法体中有一个语句检查 if ,该检查究竟是什么?HandlerInterceptorAdapter
postHandle
final HttpServletResponse response
if
response.isCommitted()
private static final String voidResponse = "null";
@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler,
final ModelAndView modelAndView) throws IOException {
if (!response.isCommitted()) {
if (DefaultServletHttpRequestHandler.class == handler.getClass()) {
return;
}
response.setStatus(200);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
try (final Writer writer = response.getWriter()) {
writer.write(voidResponse);
}
log.info("void method called, respond with 200 and null");
response.flushBuffer();
}
}