- Creating an Error Page
- Setting Error Pages with the page Directive
- Setting Error Pages by Using the web.xml Template
Setting Error Pages with the page Directive
Within each page, you have the power to define the error page. To do so, use the errorPage attribute of the page directive:
<%@page errorPage="error1.jsp" %>
This tells the page that if an exception occurs, it should automatically redirect to error1.jsp. To use this method, you must remember to enter this line of code in all your pages (you could also use the include directive to include this in the header). You also don't have the ability to send different types of errors to different error pages.
NOTE
Using error pages with the page directive works for other errors besides compilation errors. If you have any invalid syntax, such as missing semicolons, nonclosed JSP tags, or other errors in code syntax, you still get the normal error and stack trace.