Difference betn: errorPage directive and <erorr-page> in web.xml

M

may

Hi

JSP pages can define <%page errorPage="/anyerror.jsp" %> to direct
browser to anyerror.jsp page in case of unexpected error in the JSP
page.

There is also <error-page> tag that can be defined in web.xml
deployment descriptor for declaring error pages based on exception
types declared.

e.g.
<error-page>
<error-code>404</error-code>
<location>/jsp/error/PageNotFound.jsp</location>
</error-page>
<error-page>
<exception-type>java.rmi.RemoteException</exception-type>
<location>/jsp/error/ErrorPage.jsp</location>
</error-page>

I have seen that if error (e.g. Remote exception is thrown) occurs in
the JSP page, browser always redirect to anyerror.jsp and there is no
effect of what is declared in web.xml (even when a matching exception
is in the deployment descritpor). Is this correct behaviour? Please
can someone throw light on usage of these two alternatives.

Many thanks in advance for your reply

Regards
 
V

VisionSet

may said:
Hi

JSP pages can define <%page errorPage="/anyerror.jsp" %> to direct
browser to anyerror.jsp page in case of unexpected error in the JSP
page.

There is also <error-page> tag that can be defined in web.xml
deployment descriptor for declaring error pages based on exception
types declared.

e.g.
<error-page>
<error-code>404</error-code>
<location>/jsp/error/PageNotFound.jsp</location>
</error-page>
<error-page>
<exception-type>java.rmi.RemoteException</exception-type>
<location>/jsp/error/ErrorPage.jsp</location>
</error-page>

I have seen that if error (e.g. Remote exception is thrown) occurs in
the JSP page, browser always redirect to anyerror.jsp and there is no
effect of what is declared in web.xml (even when a matching exception
is in the deployment descritpor). Is this correct behaviour? Please
can someone throw light on usage of these two alternatives.

If I remember correctly, the <%@ page errorPage... tag is for catching and
redirecting errors that occur in jsp. Whilst the web.xml version catches
them in servlets.
There is a .pdf that explains all this, and also it is useful to be aware of
the exception request attributes that are automatically generated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top