👉 The exception object is NOT available in a regular JSP page.
| Object | Available in regular JSP? | Notes |
|---|---|---|
request | ✅ Yes | Always |
response | ✅ Yes | Always |
session | ✅ Yes | Always |
application | ✅ Yes | Always |
out | ✅ Yes | Always |
config | ✅ Yes | Always |
pageContext | ✅ Yes | Always |
page | ✅ Yes | Always |
exception | ❌ No | Only in error pages |
🔥 Why is exception not available?
exceptionis used to capture a thrown exception when an error occurs.- It’s only created if the JSP page is explicitly marked as an error page using this directive:
<%@ page isErrorPage="true" %>
Without that setting:
- The JSP does not know to expect an
exceptionobject. - If you try to use
exceptionon a normal page, you’ll get a compilation error.
📚 Example:
1. Normal JSP page (home.jsp)
<html>
<body>
Hello, World!
<%-- No exception object here --%>
</body>
</html>
exception ❌ not available.
2. Error JSP page (error.jsp)
<%@ page isErrorPage="true" %>
<html>
<body>
<h2>Error occurred!</h2>
<p><%= exception.getMessage() %></p>
</body>
</html>
exception ✅ available because isErrorPage=true.
🎯 Final Quick Summary:
| Object | Availability | Notes |
|---|---|---|
All other implicit objects (request, response, session, etc.) | ✅ Always available in JSP | |
exception | ❌ Only available if the page is an error page (isErrorPage="true") |