How to handle error 404 and 500 in vRaptor?

1

I have already 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 should do something else, because it's not very clear from the Caelum vraptor handouts.

    
asked by anonymous 14.07.2015 / 19:36

1 answer

2

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

<!-- 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 of the fact that we are talking about error pages, you can have access to special objects (you can even see the stacktrace in case of a 500 error for example). For more details, see this link .

    
14.07.2015 / 21:26