Bug 62471 - Cannot set status code if Servlet is used as error page
Summary: Cannot set status code if Servlet is used as error page
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.6
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-18 16:12 UTC by juri.berlanda
Modified: 2018-06-18 16:43 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description juri.berlanda 2018-06-18 16:12:40 UTC
This bug happens with Tomcat 9.0.6 and later.

9.0.5 and earlier (including the 8.5 releases) are NOT affected.

Assume the following in web.xml:

<error-page>
    <error-code>404</error-code>
    <location>/errorRedirect</location>
</error-page>

<servlet>
    <servlet-name>Error Redirect Servlet</servlet-name>
    <servlet-class>org.duckdns.owly.tomcat9test.ErrorRedirectServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Error Redirect Servlet</servlet-name>
    <url-pattern>/errorRedirect</url-pattern>
</servlet-mapping>

Tomcat 9.0.6 and later will always return a Response with status 404 if a non existing page is accessed - no matter what I do in ErrorRedirectServlet.doGet(Request, Response).

This is especially bad if one wants to send a redirect, as the location header is set, yet due to the status code not being 302 it is ignored by the browser.

I tested response.sendRedirect("error.html"), both with and without a preceding response.setStauts(302).

A small sample project is available at https://github.com/j-be/tomcat-9-redirect-test.
Comment 1 Mark Thomas 2018-06-18 16:43:08 UTC
Already fixed in trunk.