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
The problem is that you catch the Exception and therefore no Exception will leave your doPost()
method. You will only be redirected error page if an Exception
matching the
(either identical or a subclass of it) leaves your doPost()
method.
You should rethrow the Exception
bundled in a RuntimeException
for example:
} catch(Exception e) {
e1.printStackTrace();
throw new RuntimeException(e);
}
Unfortunately if we're talking about a general Exception
you can't just not catch it because doPost()
is declared to only throw instances of ServletException
or IOException
. You are allowed not to catch those, but java.lang.Exception
must be caught.