抱歉,您没有显示任何相关代码,因为您复制/粘贴的代码不对您提到的异常负责。
相关的部分是您正在使用JSP,并且没有阅读本书第9章中列出的有关JSP的重要警告。
编写JSP时,您可能喜欢空白和缩进,例如:
<% //a line of pre %><% // some more pre%><% // another line of pre %><% response.getOutputStream();%>
"getOutputStream() has already been called for thisresponse"无论是否使用iText,这总是会导致异常。
getOutputStream()当您在JSP脚本中引入第一个空白字符时,便称为该方法。
要解决此问题,您需要删除所有空白:
<% //a line of pre %><% // some more pre%><% // another line of pre %><% response.getOutputStream();%>
Not a single character is accepted outside the
<%and
%>markers. As
explained in the better JSP manuals, you shouldn’t use JSP to create binary
files. Why not? Because JSP introduces white space characters at arbitrary
places in your binary file. That results in corrupt files. Use Servlets
instead!



