How to properly send an HTTP message to the client

后端 未结 7 1283
一生所求
一生所求 2021-02-05 00:14

I\'m working on a RESTful web service in Java. I need a good way to send error messages to the client if something\'s wrong.

According to the Javadoc, HttpServlet

7条回答
  •  悲哀的现实
    2021-02-05 00:53

    After your clarification, I tried this in Tomcat. Executing

    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "message goes here");
    

    returns

    HTTP/1.1 400 message goes here
    

    as the first line in the response.

    There must be a problem with the servlet container you are using.

提交回复
热议问题