You cannot solve it. You cannot control whether the client will press Esc, or hastily click a different link, or close the browser, or have its machine crashed, etcetera, while your server is still handling the HTTP request/response.
You can "hide" it by a global filter (mapped on /*
) which does something like this:
try {
chain.doFilter(request, response);
}
catch (ClientAbortException e) {
// Ignore.
}
This however brings a servletcontainer-specfic dependency in your code. The filter in question would result in NoClassDefFoundError
on a servletcontainer of a different make which doesn't use Tomcat specific ClientAbortException
. You might want to check the class simple name instead. Make use of the advantage that it's a subclass of IOException
:
try {
chain.doFilter(request, response);
}
catch (IOException e) {
if (!e.getClass().getSimpleName().equals("ClientAbortException")) {
throw e;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…