How to redirect to error page in servlet?

前端 未结 3 1404
挽巷
挽巷 2021-01-20 13:39

I am writing the servlet , in case of exception I am redirecting to my customized error page for that i have done like this.

In web.xml



        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 14:23

    You're catching the exception, and only printing the stacktrace inside, so the error-page doesn't take affect, remove the try-catch or re-throw and it will work. In addition, you have some syntax errors. Try something like

    try{
           //Here is all code stuff
           throw new Exception();
    }catch(Exception e){
             e.printStackTrace();
             throw new ServletException();
    }
    

提交回复
热议问题