Issue
How can I override in Tomcat 7 the text of the HttpStatu
s.
I'm using HttpServletResponse.sendError(401, "Invalid username or Password")
, but when I'm looking at the response status in the client it goves 401 Unauthorized
.
Is there any way to override it?
Solution
Edit catalina.properties
and add the property:
org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER=true
With that set in my dev environment, then when I do:
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"A very very very bad request");
I see:
HTTP/1.1 400 A very very very bad request
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1024
Date: Fri, 20 Dec 2013 11:09:54 GMT
Connection: close
Answered By - Will Keeling
Answer Checked By - Robin (JavaFixing Admin)