I'm having some problems figuring out how to handle Exceptions when working with JSP / FilterServlet / ControllerServlet
I want all exceptions, no matter if they happen in JSP page/FilterServlet/ControllerServlet/Java Class to redirect the user to "error.jsp" where it shows the error name and a stacktrace of it.
This is a typical action on the site:
1. user requests "index.jsp"
2. FilterServlet checks session and gets data to display on "index.jsp"
3. when FilterServlet is done it shows "index.jsp"
1. user clicks update button
2. jquery ajax makes a post to ControllerServlet
3. ControllerServlet ask a Java Class to open a connection to mysql and make the update
4. ControllerServlet gets a boolean back from the class wheather it was a success or not
5. ControllerServlet makes a printwriter where it prints the result
6. jquery ajax reads the result and displays it to the user in a nice message under the update form.
All of the above works like it should except for when an exception occours.
right now when an error occours i just make a try catch and do nothing in the catch block.
i have tried almost all of the tutorials and examples i could find on how to handle this but none of them seams to work.
The problem might be that everything happens through jQuery AJAX, but i am not sure.
in a sidenote i am also using URLRewriteFilter, but i dont think that gives any problems when it comes to exceptions
I would be very grateful if someone here can figure this out.
I always just declare a central error handler in the deployment descriptor and never catch an exception (unless I have something special to do with it). Just let it propagate out to the container to handle it according to the deployment descriptor.
Well. yeah. When you redirect to the error page on your own, it creates a new request and no error information is available. The result of the error processing is sent to you as the Ajax response which you are alerting.