search

Home  >  Q&A  >  body text

java - Spring:Can we create custom HTTP Status codes ?

Can we create custom HTTP Status codes ?

怪我咯怪我咯2837 days ago725

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-18 10:36:24

    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

    reply
    0
  • Cancelreply