That is exactly the line I am referring to.

Simply replacing the call to res.setStatus with res.sendError would
definitely be wrong due to what you described. That change is not what I am
suggesting. It is simply what I did for a quick test. I was thinking it
would be worth it to add a flag as a servlet init-param to allow support
for the error-pages. The default would maintain current functionality so as
not to break anything currently in place.

Something like:

        if (!cgiEnv.isValid()) {
            if (shouldTriggerErrorPage) {
                res.sendError(404);
            } else {
                res.setStatus(404);
            }
        }

There are also a few other calls to setStatus that would probably be
handled the same way in order to handle other error codes as well.

As for the "if (!cgiEnv.isValid())" condition, isValid() will return false
if a request is made for a file that does not exist. Since the file doesn't
exist, I actually wanted to show a proper 404 error page matching the error
pages for the rest of my server. Currently, all I see is a blank page from
the CGIServlet since my debug level doesn't meet the logging condition.

Thanks for the help,
Jake

On Mon, Mar 16, 2015 at 7:49 PM, Konstantin Kolinko <knst.koli...@gmail.com>
wrote:

> 2015-03-16 21:52 GMT+03:00 Jacob Haverkost <jdh5...@gmail.com>:
> > Version: 6.0.43
> > OS: Win7 x64
> >
> > Currently, the CGIServlet does not appear to support using the 404
> > error-page specified in the web.xml (ROOT). The error-pages work fine
> >
> > This appears to be due to the line, res.setStatus(404);, inside of
> doGet().
> > According to the documentation for HttpServletResponse.setStatus(int),
> "If
> > this method is used to set an error code, then the container's error page
> > mechanism will not be triggered."
> >
> > This line appears in all major versions of Tomcat that I have looked into
> > (8.0.20, 7.0.59).
> >
> > Just for a quick test, I changed setStatus to sendError and the
> error-page
> > worked as expected. Is there a way to have the error-page work without
> > changing the source code? If not, should I submit a bug report to
> include a
> > configuration parameter for the CGIServlet to allow support for the
> > error-page?
> >
>
> If you are talking about the following: (lines 612-614 in CGIServlet
> of current Tomcat 6.0.x)
>
>         if (!cgiEnv.isValid()) {
>             res.setStatus(404);
>         }
>
>
> You cannot just change res.setStatus(404);  with res.sendError(404),
> as that will break the following code that generates a HTML page with
> a debug message.
>
> See the block starting with "if (debug >= 10)".
>
>
> My guess (without looking deep into this) is that "if
> (!cgiEnv.isValid())" condition is there to catch a configuration
> error. I mean that you would not see that with a properly configured
> CGIServlet.   If my guess is wrong, you need to provide a specific use
> case that demonstrates otherwise.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to