tags:

views:

46

answers:

1

Not a jsp/maven/java dev myself, i'm trying to configure error pages in a generic way, for a webapp, without touching jboss's configuration.

Here's how i'm trying to do so: in my web.xml, i've set up

    <error-page>
        <error-code>*</error-code>
        <location>/actions/erreur</location>
    </error-page>

Here, I doubt using '*' works, but that's for the example. Then, in my strut-config.xml

    <action path="/erreur" forward="erreurView" />

And finally in my tiles-def.xml:

<!-- ERREURS  -->
<definition name="erreurView" extends=".formPremiereConnexionLayout">
    <put name="titrePage" value="Erreur"/>  
    <put name="body" value="/jsp/erreurs.jsp"/>
</definition>

You get the idea, if you have an appropriate answer, thanks for the help.

One last thing : even though any server error code send to a generic error view, i'd like to detail the error in the jsp. I think a scriptlet would do fine, buyt once again, I have no idea on how to do so. Thanks.

+3  A: 

The wildcard wouldn't work. How verbose, you really need to define the status codes of interest separately. E.g.

<error-page>
    <error-code>403</error-code>
    <location>/actions/erreur</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/actions/erreur</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/actions/erreur</location>
</error-page>
...

The last one listens on all exceptions/errors the server could throw. However you can't be sure if it will ever be displayed on a java.lang.Error.

Inside the error page you can get the important details from the request scope and headers like so:

<p>Request URI: <c:out value="${requestScope['javax.servlet.forward.request_uri']}" /></p>
<p>Exception type: <c:out value="${requestScope['javax.servlet.error.exception']}" /></p>
<p>Exception message: <c:out value="${requestScope['javax.servlet.error.message']}" /></p>
<p>HTTP status code: <c:out value="${requestScope['javax.servlet.error.status_code']}" /></p>
<p>HTTP user agent: <c:out value="${header['user-agent']}" /></p>

If you want to print the stacktrace as well, you'll have to prepare this inside a servlet/beanclass by writing it to a String and putting it in the request scope and finally display it in a <pre></pre>.

BalusC
Why is the upvote switchted to a downvote after updating the answer? Are there better ways to display the trace (without using scriptlets)? You could just say that so, so that we can all learn from the mistake.
BalusC
Msitake, just a click mistake.Yet, <exception-type>java.lang.Throwable</exception-type>seems to cacth only 500's , how about generic 400's ?
pixelboy
Yes, you would like to define them separately. I updated the answer accordingly. If your actual intent was to remove an upvote, you can just click the orange arrow once again to undo it.
BalusC