Error "getoutputstream () has already been called for this response" when opening pdf

0

I have this code that what it does is open a PDF that is in a route. When opening this file, it actually opens it, but in console it shows me the error of getoutputstream() has already been called for this response and it is annoying because it can generate future errors. I have not managed to make that error happen and that's why I'm looking for help.

        <%@page import="java.io.FileInputStream"%>
        <%@page trimDirectiveWhitespaces="true"%>
        <%@ page language="java" contentType="application/pdf; charset=UTF-8" pageEncoding="UTF-8"%>
        <%@ page import= "java.io.*" %>
        <%

            boolean error=false;
            try {
                String nombreArchivo=request.getParameter("doc");
                Archivos archivo= new Archivos();
                FileInputStream ficheroInput = new FileInputStream("C:\archivo\archivo.pdf");
                int tamanoInput = ficheroInput.available();
                byte[] datosPDF = new byte[tamanoInput];
                ficheroInput.read( datosPDF, 0, tamanoInput);

                response.reset();
                response.resetBuffer();
                response.flushBuffer();
                response.setHeader("Content-disposition","inline; filename=unrt.pdf" );
                response.setContentType("application/pdf");
                response.setContentLength(tamanoInput);
                response.getOutputStream().write(datosPDF);

                ficheroInput.close();

            } catch (Exception e) {
                error=true;
            }
        %>

        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Visor PDF</title>
        </head>
        <body>
        <% if(error){
        %>   
            <h1>Ocurrió un error al cargar el archivo</h1>
        <%}
        %>
        </body>
        </html>
    
asked by Jonathan ch 11.01.2018 в 22:14
source

0 answers