如何在Console上停止打印异常堆栈跟踪?
我编写了一个servlet来处理我的Web应用程序中发生的异常,并将它们映射到web.xml中
I wrote a servlet to handle the exceptions occurring in my web app and mapped them in web.xml
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/exceptionHandler</location>
</error-page>
以下是我在异常处理servlet中所做的 service
方法:
Here is what I have done in the Exception Handling servlet service
method:
@Override
protected void service(HttpServletRequest req, HttpServletResponse arg1)
throws ServletException, IOException {
Object attribute = req.getAttribute("javax.servlet.error.exception");
if(attribute instanceof SocketException){
// don't do anything
}else{
super.service(req, arg1);
}
}.
问题:
上述方法无效,堆栈跟踪正在打印到控制台。当用户请求某些内容然后关闭其浏览器时会发生这种情况。
The above approach is not working and the stack trace is printing to the console. This occurs when the user requests something and then closes their browser.
问题:
每当发生 SocketException
时,如何停止将printtrace打印到JBoss控制台?
How do I stop printing the stacktrace to the JBoss console whenever a SocketException
occurs?
原因为此:
我想避免在最后看到所有日志的 SocketException
因为我对这些信息无能为力。
I want to avoid seeing all of the log's SocketException
s at the end of th day because I can't do anything with that information.
而不是添加 java。您的web.xml中的lang.Exception
为什么不尝试在web.xml本身添加套接字异常,如下所示
Instead of adding java.lang.Exception
in your web.xml why won't you just try to add socket exception in web.xml itself like below
<error-page>
<exception-type>java.net.SocketException</exception-type>
<location>/exceptionHandler</location>
</error-page>
并且只在您的servlet中执行任何操作
或而是添加一个空的jsp文件,比如
and just do nothing in your servlet
Or instead add a empty jsp file like
<error-page>
<exception-type>java.net.SocketException</exception-type>
<location>/error.jsp</location>
</error-page>