How do I use getOutputStream() and getWriter() in the same servlet request?

后端 未结 2 765
深忆病人
深忆病人 2021-01-07 03:56

How do I use getOutputStream() and getWriter() in the same servlet request?

2条回答
  •  时光取名叫无心
    2021-01-07 04:38

    You can use them both, just not at the same time, or rather not for the same response. If you need to use a Writer after you've already started using the OutputStream, just wrap an OutputStreamWriter around the output stream. However if you need to use an output stream after you've already used the writer you can't. You could always get the output stream first, wrap the writer around it as above, do your Writing, flush, then do your output streaming.

提交回复
热议问题