- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle error object in JSP using JSTL tags?
You can make use of JSTL tags to write an error page ShowError.jsp with better structure and more information −
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <%@page isErrorPage = "true" %> <html> <head> <title>Show Error Page</title> </head> <body> <h1>Opps...</h1> <table width = "100%" border = "1"> <tr valign = "top"> <td width = "40%"><b>Error:</b></td> <td>${pageContext.exception}</td> </tr> <tr valign = "top"> <td><b>URI:</b></td> <td>${pageContext.errorData.requestURI}</td> </tr> <tr valign = "top"> <td><b>Status code:</b></td> <td>${pageContext.errorData.statusCode}</td> </tr> <tr valign = "top"> <td><b>Stack trace:</b></td> <td> <c:forEach var = "trace" items = "${pageContext.exception.stackTrace}"> <p>${trace}</p> </c:forEach> </td> </tr> </table> </body> </html>
Access the main.jsp, the following will be generated −
Opps...
Error: | java.lang.RuntimeException: Error condition!!! |
URI: | /main.jsp |
Status code: | 500 |
Stack trace: | org.apache.jsp.main_jsp._jspService(main_jsp.java:65) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) |
- Related Articles
- What are JSTL Core tags in JSP?
- What are JSTL formatting tags in JSP?
- What the different types of JSTL tags are ?
- How to handle SSL certificate error using Selenium WebDriver?
- How to create a common error page using JSP?
- How to handle an exception in JSP?
- How to send an error code using JSP to browser?
- How to handle Assertion Error in Java?
- How to handle jQuery AJAX error?
- Is there any JSTL library to parse XML in a JSP?
- How many types of directive tags JSP supports?
- How to declare an object of a class using JSP declarations?
- I want to use %> literal in JSP page. But it is throwing error. How to escape this syntax in JSP?
- How to remove empty tags using BeautifulSoup in Python?
- How to handle the error “Text strings must be rendered within a component” in ReactNative?

Advertisements