views:

147

answers:

2

I've defined <%@ page errorPage="/error.jsp" %> in the header that all JSP files include, to catch any unhandled exceptions and redirect to that error page instead of printing them. This works fine with one caveat - if error.jsp itself throws an exception, it will continuously redirect to itself in an infinite loop. I want to erase the errorPage value for just error.jsp so that it'll just print the exception as normal. I tried just redefining the errorPage property to be blank but I get the following error:

Page directive: illegal to have multiple occurrences of errorPage with different values (old: /error.jsp, new: )

Is there any way for me to overwrite that property? Or any other suggestions on how to prevent this issue?

+1  A: 

It is indeed illegal to have multiple page declarations with the same attribute. Your choices are:

  1. Not include your header into your error page.
  2. Ensure that your error page doesn't throw any exception on its own. It should really be rather simple and straightforward - error page is no place for business logic. If you want to do something complicated there, consider redirecting to another page instead.
ChssPly76
A: 

Why don't you just have a different include header for the error page which do not include it himself?!!

So, instead of having:

header.jsp
==========
a
b
c
errorPage=error.jsp

You could have:

commonHeader.jsp
===========
a
b
c

Without the errorPage directive

And modify the header to include the new one.

header.jsp
===========
include=commonHeader.jsp
errorPage=error.jsp

That way you don't need to change anything in the rest of your jsp's

You just need to change your errorPage from:

 include="header.jsp"

to

 include="commonHeader.jsp"

And the errorPage won't have an error page anymore ....

OscarRyz
Yeah, the main reason I didn't want to mess with the include is because having multiple versions(or inlining the code) could cause confusion/bugs in the future if somebody updates it without knowing about my version. It would certainly work though.
Andrew K
That will only happen on error.jsp on the remaining you'll have the same control ( or mess ) you currently have, nothing change from the outside
OscarRyz