如何在Console上停止打印异常堆栈跟踪? [英] How to stop printing exception stack trace on Console?

查看:538
本文介绍了如何在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 SocketExceptions 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>

这篇关于如何在Console上停止打印异常堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆