Jsp Custom Error Pages
Contents |
versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development Creating Custom Error PagesDefining jsp iserrorpage error pages in web.xmlConfiguring error pages context filesCustom ErrorHandler classServer tomcat error page location level 404 errorThe following sections describe several ways to create custom error pages in Jetty.Defining jsp error page tag error pages in web.xmlYou can use the standard webapp configuration file located in webapp/WEB-INF/web.xml to map errors to specific URLs with the error-page element. This element
Web.xml Error-page Exception-type
creates a mapping between the error-code or exception-type to the location of a resource in the web application.error-code - an integer valueexception-type - a fully qualified class name of a Java Exception typelocation - location of the resource in the webapp relative to the root of the web application. Value should jsp error handling and debugging start with /.Error code example:
QuestionsJava Interview QuestionsJDBC Interview QuestionsServlet Interview QuestionsJSP Interview QuestionsStruts2 Interview QuestionsSpring Interview QuestionsHibernate Interview QuestionsJSF Interview QuestionsResourcesStoreHome » Java » Java EE » JSP Exception Handling - JSP Error PageJSP Exception Handling - JSP Error PageSeptember 11, web.xml error-page location 2016 by Pankaj 3 Comments Exception handling in JSP is done
Jsp Error Page Status Code
by JSP exception pages.Exception Handling in JSPSometime back I wrote a post about Servlet Exception Handling and why
Exception Handling In Jsp Servlet Application
do we need it. Same explanation is also applicable for JSP pages also and that's why Java EE provides a clear approach for exception handling in JSP using JSP http://www.eclipse.org/jetty/documentation/9.3.x/custom-error-pages.html error pages.To handle exceptions thrown by the JSP page, all we need is an error page and define the error page in JSP using jsp page directive.JSP Error PageTo create a JSP error page, we need to set page directive attribute isErrorPage value to true, then we can access exception jsp implicit object in the JSP and use it http://www.journaldev.com/2049/jsp-exception-handling-jsp-error-page to send customized error message to the client.JSP Error Page ConfigurationWe need to set page directive errorPage attribute to define the JSP that will handle any exception thrown by the JSP service method. When JSP Error page is translated to servlet code, it extends org.apache.jasper.runtime.HttpJspBase in Tomcat.Error Page Deployment Descriptor ConfigurationMost of the times, we have a common error page that we want to use for all the JSPs, so rather than configuring it in all the JSPs individually, we can define error page in web.xml with error-page element. We can configure JSP error page to handle other error codes like 404 also.Let's see how all these fit together in a web application.We will create a simple web application JSPExceptionHandling whose project structure will look like below image. The entry point of the application is index.jsp whose code is given below. <%@ page language="java" contentType="text/html; charset=US-ASCII" pageEncoding="US-ASCII"%>