java中的Servlet - getWriter()和getOutputStream() [英] Servlets in java - both getWriter() and getOutputStream()

查看:172
本文介绍了java中的Servlet - getWriter()和getOutputStream()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在 ServletResponse 的实例上, getWriter() getOutputStream ()无法调用?

Why is it that on an instance of ServletResponse both getWriter() and getOutputStream() can't be called?

推荐答案

设计决策。 Writer和OutputStream都维护自己的缓冲区。如果你创建了一个,那么他们的输出需要以某种方式合并。可能,但更复杂。所以他们决定你必须选择是否需要基于字符的输出或二进制输出。

A design decision. The Writer and the OutputStream both maintain their own buffer. If you created one each then their output would need to be merged somehow. Possible, but more complicated. So they decided that you have to choose if you want character-based output or binary output.

这篇关于java中的Servlet - getWriter()和getOutputStream()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆