Spring:Can we create custom HTTP Status codes ?

Can we create custom HTTP Status codes ?

阅读 2.6k
1 个回答

Ofcourse, you can use raw servlet api HttpServletResponse,

@RequestMapping("test")
public void test(HttpServletResponse response) throws IOException {
    response.setStatus(10000); // http status code 10000(NOT EXISTS)
    response.flushBuffer();
}

But is's not recommend to use a HTTP status code that does not exists,
cause the clients don't know what it means

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题