• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error pages

 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following:

web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ch9</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>serv</servlet-name>
<servlet-class>Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>serv</servlet-name>
<url-pattern>/Serv.do</url-pattern>
</servlet-mapping>

<error-page>
<exception-type>java.lang.ArithmeticException </exception-type>
<location>/error.jsp</location>
</error-page>

</web-app>

//-------------------------------------------------------------

and i have this jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<strong>ERROR</strong>
You caused an ${pageContext.exception }
</body>
</html>
//------------------------------------------------------------------

In HF book it states if the jsp does not have the page directive and attribute isErrorPage set to true it doesnt have the implicit exception object.

But when i hit the jsp that gives me an ArithimeticException it forwards to the error.jsp. In error.jsp it uses the implicit object and prints info about the exception. As i understood, it should not print anything since i dont have the exception implicit object. Can someone help me on this?

regards
Gunnar
 
Amar Nath Verma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set isErrorPage = true , then you can directly access the 'exception' implicit variable.

here you are accessing the 'pageContext' implicit variable available to EL, which you can do in any page.

If you try to access 'exception' implicit variable here you will get an exception. It will work only if you set <%@ page isErrorPage = true %> in the page
 
Amar Nath Verma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One correction:
If you use 'exception' implict variable without setting isErrorPage true, you will get a jsp compilation error
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic