How to treat error 404 and 500 in vRaptor?

Asked

Viewed 584 times

1

I have seen tutorial of vraptor4 teaching to put this error in web.xml, to redirect, the following xml code:

<error-page>
    <error-code>404</error-code>
    <location>/404.jsp</location>
</error-page>

Can I put this code anywhere on the web.xml that it works normal? Or I must do something else, because for the booklets of the vraptor of Caelum it is not very clear this part.

1 answer

2


If you are talking about the error-page of the Servlets specification, up to version 2.5, within the web-app tag (the main tag of the web.xml file that sits within WEB-INF) there is the possibility that you have one or more error-page tags, e.g.:

<!-- não encontrado -->
<error-page>
    <error-code>404</error-code>
    <location>/404.jsp</location>
</error-page>

<!-- erro interno -->
<error-page>
    <error-code>500</error-code>
    <location>/500.jsp</location>
</error-page>

If it is from Servlet 3.0, you can generalize by doing:

<!-- qualquer erro -->
<error-page>
    <location>/minhaPaginaDeErro.jsp</location>
</error-page>

Taking advantage that we are talking about error pages, you can have access to special objects (you can even see the stacktrace in case of error 500 for example). For more details, see this link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.