java - Disable all default HTTP error response content in Tomcat -
By default, Tomack sends back some HTML content to the client if it finds something similar to an HTTP 404. I know that < web.xml a & lt; Error-page & gt; to customize this content.
However, I just do not want to send Tommakat to reference content anything (I still prefer status codes). Is there a way to easily configure it?
I am trying to avoid A. Clearly sending empty content to my feedback response stream from my servlet, and b) Configuring custom error pages for a whole bunch of HTTP errors in my web.xml
For some backgrounds, I am developing an HTTP API and controlling my own feedback content. Therefore, for an HTTP 500, for example, I am populating some XML content on the error response information. For situations like HTTP 404, HTTP response status is sufficient for the client, and sending content tokkets is unnecessary. If there is a different approach, then I am open to hearing it.
Edit: After continuous investigation, I still can not find much in the way of a solution. If someone can say that it is not possible, or provide a resource with proof that it will not work, then I accept it as an answer and will try to work around it.
If you do not want to display an image in an error page, sendError (... ). Use setStatus instead (...)
For example, if you want to give 405 feedback, you do
response.setStatus (HttpServletResponse.SC_METHOD_NOT_ALLOWED ); Feedback.getWriter (). Println ("method" + request.getMethod () + "is not supported by this service."); Also remember that not throwing an exception with your servlet. Instead, grab the exception and, again, set the position to yourself.
i.e.
Secure zero service (HTTPSvette request), IOException throws {try {// servlet code here, eg Super.service (request, response); } Hold (Exception E) {// Log Error with a Timestamp, Show timestamp to user for long time = System.currentTimeMillis (); Logs ("exception" + now, e); Response.setStatus (HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Feedback.getWriter (). Println ("Master Meditation:" now); }} Of course, if you do not want any content, then the author does not want to write anything, just set the status.
Comments
Post a Comment