Custom 404 with jsp

First of all, you've to insert in the web xml this lines:

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


In this way tha application server when doesn't find a resource it will pass the ball to the error page.
When the server forward to the error page it passes same attribute in the request, like:

Attribute

Type

javax.servlet.error.status_code

java.lang.Integer

javax.servlet.error.exception_type

java.lang.Class

javax.servlet.error.message

java.lang.String

javax.servlet.error.exception

java.lang.Throwable

javax.servlet.error.request_uri

java.lang.String

javax.servlet.error.servlet_name

java.lang.String


It will be enough, in the error page, to show something a message like this:
The requested reource <%=request.getAttribute("javax.servlet.error.message")%> has not be found!

Obviously, the same things are valid for the others HTTP errors, like 500, 400, and so on.

Nessun commento:

Posta un commento