I have used write bean tag in jsp file but when i try to create output stream using response object then it gives IllegalStateException?

huangapple go评论77阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年4月8日 18:03:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/61098087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定