How to redirect to error page when exception occurs from servlet?

后端 未结 3 1174
终归单人心
终归单人心 2021-01-12 20:24

I am writing a servlet, in that if any exception occurs i donэt want to display exception/error message on browser, so I will redirect to my customized error page. So I have

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 20:49

    One way to handle it in a generic way is to use web.xml like below:

    
        java.io.IOException
        /ErrorHandler
    
    

    I have just included IO exception but you might have say SQLException you could very well add another error-page and another location for the same. Similarly you could say java.lang.Exception type and one handler handling everything.

提交回复
热议问题