这是一个众所周知的行为,当抛出异常并且已经提交响应时会发生这种行为。
通常会记录异常,但在某些特定情况下不会。
我读到你解决了删除 EncodingFilter 的问题,但如果你仍然想找到问题,你可以尝试编写一个过滤器,它必须在 EncodingFilter 之前执行,它将 response.setBufferSize 设置为更大的大小。
这可以是这样一个过滤器:
public class ResponseBufferFilter implements Filter
{
private FilterConfig filterConfig;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
try
{
// or better take the value from filterConfig.getInitParameter
response.setBufferSize(100000000);
chain.doFilter(request, response);
}
catch(Exception e)
{
e.printStackTrace();
throw new ServletException(e.getMessage(), e);
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig = filterConfig;
}
@Override
public void destroy()
{
filterConfig = null;
}
}
这是映射:
<filter>
<filter-name>Response Buffer Filter</filter-name>
<filter-class>test.example.filter.ResponseBufferFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Response Buffer Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<!-- provide the class causing unwanted behavior -->
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这不会解决问题,但至少它应该允许以一种或另一种方式记录异常,如果有的话。