smile_juan
smile_juan

Reputation: 41

error-page setting in web.xml doesn't work

In my portlet, I'd like to handle all exception in one way. Config error-type in web.xml. Here is my code in web.xml

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/WEB-INF/jsp/error.jsp</location>
</error-page>

error.jsp

<%@ page isErrorPage="true"%>
no available now!

when nullpointerexception happens, it doesn't go to my error.jsp page.

Upvotes: 1

Views: 622

Answers (2)

Marcel St&#246;r
Marcel St&#246;r

Reputation: 23555

location - location of the resource in the web app relative to the root of the web application. Value should start with /.

Hence, the file must not be in WEB-INF.

Sidenote: I prefer my error pages to be simple HTML pages instead of JSP. What if compiling/rendering the error JSP fails? An error while displaying an error page is not ideal.

If you like this answer you may upvote or accept it.

Upvotes: 0

Subin Sebastian
Subin Sebastian

Reputation: 10997

Try putting your error.jsp outside WEB-INF folder say webapps/contextDIR

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>

Upvotes: 1

Related Questions