John Lindal’s Blog
Improved Error Reporting in JSP’s
February 4, 2009 on 10:03 am | In Programming | No CommentsJSP’s are a pain because all errors go to the server log instead of the screen. This is not conducive to rapid iteration. In my quest to fix this, I first added a catch (ServletException ex) block to the first filter in the chain defined in my web.xml.
Then I discovered that Tiles swallows errors in included JSP’s. This blog confirmed my conclusions from researching into the Tiles source code. You need to implement a custom JspTilesRequestContext. I prefer to configure via web.xml rather than Spring. It works either way. Note that for Tiles 2.0.x, the online documentation is wrong! The key is org.apache.tiles.context.ChainTilesContextFactory.FACTORY_CLASS_NAMES, not org.apache.tiles.context.ChainedTilesContextFactory.FACTORY_CLASS_NAMES. The latter only works for Tiles 2.1.x.
Another important issue is that displaying an error page only works if no output has been committed. If some output has already been written, you have to append to that. Through trial and error, I discovered that the following will close all possible traps, so the error output will always be visible:
""></script></style></head>
Before Tiles 2.0.6, JspTilesRequestContext throws a plain IOException. For JDK 1.5, this cannot contain a cause, so you must look at the logs for the original exception. Tiles 2.0.6 introduces TilesIOException which does include the cause. This cause is always a ServletException.
The exception that my code actually catches is usually an onion. To get at the root problem, you need to drill in until you find an exception with null cause. To make it more confusing, you must call getRootCause() on ServletException and getCause() on all other exceptions. In order to get a line number in the JSP, you must print all intermediate exceptions. One of them will usually include an excerpt from your JSP.
No Comments yet »
RSS feed for comments on this post.
Leave a comment
You must be logged in to post a comment.
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^