Topic
  • 1 reply
  • Latest Post - ‏2013-02-01T09:32:36Z by SystemAdmin
SystemAdmin
SystemAdmin
106 Posts

Pinned topic How to override http status code in HttpServletResponse

‏2008-02-27T19:13:12Z |
Hi,

Checking in case anybody knows abt it.

Here is what i want to do inside a J2EE 1.4 servlet. I am getting Http status code 500, but I want it to change it to some meaningful status code like 400,404, or 405 (depending where its being thrown) inside a servlet instead of throwing 500. I call setStatus() method on HttpServletResponse, but it doesn't seem to work. It still displays "Http status code 500" in the browser. I am really stucked here, any help will really be appreciated.

Here is the code for the above mentioned problem:
if (operation == null) {
// the requested operation does not exist in the configuration
String errorMsg = "some error");
response.setStatus(404);
throw new ServletException(errorMsg);
}

I am not doing something right here. Can anyone plz provide me some guidance. Thanks.
Updated on 2013-02-01T09:32:36Z at 2013-02-01T09:32:36Z by SystemAdmin