Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tomcat does not show error message when sendError used from servlet

Ok so I have a pretty simple webapp using a Servlet and in some cases I send and error back to the client like:

response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Did not specify parameter xyz");

This works fine in general but Tomcat(6.0.33 and Java 1.6.0_26-b03) does not show the given error message from above.

If I run the application on a different container like glassfish the given message is shown.

So, example output ....

Tomcat:
400 - Bad Request

Glassfish:
400 - Did not specify parameter xyz

Is it possible to configure tomcat to behave in the same way?

like image 490
rat Avatar asked Feb 02 '23 11:02

rat


1 Answers

Ok after some more digging I found the solution here: How to properly send an HTTP message to the client

You need to set:

org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER = true

in /conf/catalina.properties

This causes tomcat to send the error message you set in the headers 'properly' :)

like image 166
rat Avatar answered Apr 30 '23 06:04

rat