I've just started to using .tag files to componentize parts of a
JSP application, as well as clean some scriptlets out of the main .jsp file, and I've begun to run into some issues, particularly when there is an error that occurs in the code contained in the tag file.
I have an error.jsp page, that uses the directive <%@page isErrorPage="true" %>
On my main .jsp page (wizard.jsp), it uses the directive <%@ page errorPage="/common/jsp/error.jsp" %> and indeed correctly references the error page.
In wizard.jsp I created the following scriptlet in order to force an exception:
<%
if(true)
throw new SQLException("Message");
%>
In this case, when I try to load the page, it correctly forwards the exception to the error.jsp page which is displayed (as opposed to displaying the wizard.jsp page).
Let's try another case though. Lets say I have a tag library referenced in my wizard.jsp and prefixed "my", with a tag called "item" (<my:item/>)
This tag is defined in /WEB-INF/tags/item.tag. Now, I've removed the above scriptlet from the wizard.jsp page, and put it instead in the item.tag file, and then make reference to this tag file in my wizard.jsp.
Now, I try to load wizard.jsp. Now, instead of being forwarded to the error page due to the exception, the error.jsp page is rendered AS THE CONTENT OF THE TAG. and placed directly IN THE wizard.jsp. When I look at the page source via the browser, the markup of wizard.jsp that precedes that tag is given as normal, then <my:item/> is replaced by all of the markup of the errorpage, then STOP. The markup of wizard.jsp that occurs BELOW the <my:item/> doesn't exist.
My question: How do I get the act of an exception thrown in the body of a tag file to actually forward me to the error.jsp page, instead of rendering the error page as the content of the tag?
Followup: If I remove the errorPage page directive in my wizard.jsp file, the exception is then handled by the
servlet, and dumped to a log:
Stacktrace:
org.apache.jasper.JasperException: An exception occurred processing JSP page /wizard/wizard.jsp at line 23
20: <div class="title">
21: Wizard
22: </div>
23: <my:item/>
24: </body>
25:
26: </html>
It doesn't tell me where the error in the code really is. It just tells me where in the .jsp file the tag which contains the error is called, as opposed to where in the .tag file exception is actually thrown. If you have nested tags, this is especially useless, as you have no idea in which child, or grandchild tag the error actually is.
Can anyone help me wrap my head around proper exception handling when using tag files? It just seems silly that it seems to kind of break the expected behavior of .jsp exception handling...