Why can't HttpServletResponse Headers be updated AFTER getWriter() is called?

后端 未结 2 433
攒了一身酷
攒了一身酷 2021-01-12 07:36

I\'ve been digging around the web after fixing an issue this afternoon @ work where Cookies added to the HttpServletResponse weren\'t being properly reflected in the respons

2条回答
  •  醉酒成梦
    2021-01-12 08:05

    Because the headers precede the body in HTTP. That's why they're called 'headers'. If you call getWriter() you are writing to the body, so afterwards it is too late to start changing response header values.

提交回复
热议问题