英文:
I have used write bean tag in jsp file but when i try to create output stream using response object then it gives IllegalStateException?
问题
我在 JSP 文件中使用了写入 bean 标签,但当我尝试使用响应对象创建输出流时,它会抛出 IllegalStateException。
如何解决才能正确创建输出流并运行代码。
提前感谢您。
英文:
I have used write bean tag in jsp file but when i try to create output stream using response object then it gives IllegalStateException.
What is the solution to create output stream and run the code correctly.
Thanks in advance
答案1
得分: 0
ServletReponse
对象提供了两个方法,getWriter
用于输出文本数据,getOutputStream
用于输出二进制数据。
只能调用其中一个,否则会抛出 IllegalStateException。
在 JSP 中,当需要输出任何文本时,翻译后的代码调用 getWriter
,因此您遇到了错误。
要在 JSP 文件中调用 response.getOutputStream
,您必须确保在调用之前不需要编写任何文本,因此您必须清除所有 <% %>
标记之外的文本,甚至是 JSP 指令之间的 换行
字符。
英文:
The ServletReponse
object provides two methods, getWriter
to output text data, and getOutputStream
to output binary data.
Only one of them can be called, otherwise an IllegalStateException is thrown.
In a JSP, the translated coded calls getWriter
when needs to output any text, hence the error you are getting.
To call response.getOutputStream
in a JSP file you have to make sure that no text needs to be written prior to the call, so you have to get rid of all text outside the <% %>
marks, even new line
chars between JSP directives.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论