user994165
user994165

Reputation: 9502

JSP Error Pages

Is there a way to have a custom error page while maintaining the HTTP error code (not capturing the error with an error page that itself has a 200 code)? Can that have to be done using the in web.xml or can I do that directly in the JSP?

If I send an HTTP error code using response.sendError then no other text appears on the page. I am able to get text on the page using out.println() but it doesn't seem to be able to print out html, just basic text.

Upvotes: 0

Views: 1074

Answers (2)

thejartender
thejartender

Reputation: 9379

Yes in your web.xml you can configure error codes with the 'error-page' tag and child elements of 'error-code' and 'location'

<error-page>
   <error-code>400</error-code>
   <location>/WEB-INF/jsp/errorpages/errorPage400.jsp</location>
</error-page>

Upvotes: 2

gcochard
gcochard

Reputation: 11744

You should use response.setStatus(int statusCode) to set the status to 404 while still allowing you to send your custom error page.

Upvotes: 1

Related Questions