java.lang.IllegalStateException: getOutputStream () уже был вызван для этого ответа в jsp - PullRequest
0 голосов
/ 25 мая 2018

"Я получаю 'java.lang.IllegalStateException: getOutputStream () уже был вызван для этого ответа' исключение."

Я хочу напечатать сертификаты всех пользователей, принадлежащих к классуxxxx.Предположим, у classxxx 4 пользователя, поэтому все 4 сертификата пользователя должны печататься по одному.

Но мой код печатает только сертификат первого пользователя.

Вот мой код.

String type = "certification";
List<LBUser> classRoster = null;
classRoster = LBUser.getClassRoster(classId,true,false,false);
//Here i get list of users

if(classRoster != null && classRoster.size() > 0) {
for(LBUser user : classRoster) {

if ("certification".equals(type)){%>
<%@ include file="certificate_certification.jsp" %>
<%} %>
<%

ByteArrayOutputStream buffer = new ByteArrayOutputStream();

try { 
Document document = new Document(PageSize.LETTER.rotate());
PdfWriter writer = PdfWriter.getInstance(document, buffer);
writer.setPdfVersion(PdfWriter.VERSION_1_6); 

document.open();
PdfContentByte over = writer.getDirectContent();
PdfContentByte under = writer.getDirectContentUnder();

//Some image related and Pdf related code

document.close(); 

DataOutput dataOutput = new DataOutputStream(response.getOutputStream());
//response.getOutputStream().... Here am getting same object
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for(int i = 0; i < bytes.length; i++)
{
    dataOutput.writeByte(bytes[i]);
}

}catch(Exception e){
    e.printStackTrace();
}finally{
    try{
        if(buffer != null){
            buffer.close();
            buffer = null;
        }
    }catch(IOException e){
        buffer = null;
    }       
}
} // classRoster forloop closed

"Эта ошибка уже присутствует в Google, и я выполняю все шаги, но ничего из этого не сработало."

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...