Explanation Exception is a JSP implicit variable
The exception variable contains any Exception thrown on the previous JSP page with an errorPage directive that forwards to a page with an isErrorPage directive.
Example:
If you had a JSP (index.jsp) which throws an exception (I have deliberately thrown a NumberFormatException by parsing a String, obviously you wouldn't write a page that does this, its just an example)
<%@ page errorPage="error.jsp" %>
<% Integer.parseInt("foo"); //throws an exception %>
This will forward to error.jsp,
If error.jsp was
<%@ page isErrorPage = "true"%>
<body>
<h2>Your application has generated an error</h2>
<h3>Please check for the error given below</h3>
<b>Exception:</b><br> <font color="red"><%= exception.toString() %></font>
</body>
Because it has the
<%@ page isErrorPage = "true"%>
page directive, the implicit variable exception will contain the Exception thrown in the previous jsp So when you request index.jsp, the Exception will be thrown, and forwarded to error.jsp which will output html like this
<body>
<h2>Your application has generated an error</h2>
<h3>Please check for the error given below</h3>
<b>Exception:</b><br>
<font color="red">java.lang.NumberFormatException: For input string: "foo"</font>
</body>
As @JB Nizet mentions exception is an instanceof Throwable calling exception.getMessage() For input string:
"foo" instead of java.lang.NumberFormatException: For input string: "foo"
94 Given this fragment in a servlet:
23. if(reg.isUserInRole("Admin")) {
24. // do stuff
25. }
And the following fragment from the related Java EE deployment descriptor:
812. <security-role-ref>
813. <role-name>Admin</role-name>
814. <role-link>Administrator</role-link>
815. </security-role-ref>
900. <security-role>
901. <role-name>Admin</role-name>
902. <role-name>Administrator</role-name>
903. </security-role>
What is the result?
(A) Line 24 can never be reached. (B) The deployment descriptor is NOT valid. (C) If line 24 executes, the user's role will be Admin. (D) If line 24 executes, the user's role will be Administrator. (E) If line 24 executes, the user's role will NOT be predictable.