[RESOLVIDO]Abrir um pdf na tela web, mas com outra aba

1 resposta
H

Ola Pessoal,

Com o código abaixo eu consigo abrir uma página de pdf na web, funciona 100%, mas se eu quiser abrir a pagina de pdf em outra aba, como eu faço? Hoje eu uso Struts2.

//Pega o arquivo pdf e exibi na tela no usuário
       File file = new File(caminho + java.io.File.separator+ arqTmp);
       byte[] arquivo = fileToByte(file);

       response.setContentLength(arquivo.length);
       ServletOutputStream ouputStream = response.getOutputStream();
       ouputStream.write(arquivo, 0, arquivo.length);
       ouputStream.flush();
       ouputStream.close();

    //Converte o arquivo para byte
    private static byte[] fileToByte(File imagem) throws Exception {
        FileInputStream fis = new FileInputStream(imagem);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[8192];
        int bytesRead = 0;
        while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
                baos.write(buffer, 0, bytesRead);
        }
        return baos.toByteArray();
    }

Tem como definir no ServletOutputStream que eu devo abrir em outra aba do browser?

Obrigado

1 Resposta

H

Consegui resolver dá seguinte forma, alterei a forma de chamar a action do Struts2 acrescentando target=“blank” na chamada do relatório.

<s:form action="relatorio" namespace="/" method="POST" target="blank">
             <s:submit type="button" label="Gerar Relatório"/>
         </s:form>

Valeu.

Criado 28 de setembro de 2011
Ultima resposta 28 de set. de 2011
Respostas 1
Participantes 1