【问题标题】:doc file not displayed in jspjsp中不显示doc文件
【发布时间】:2013-10-05 07:38:04
【问题描述】:

我正在做一个 JSP 站点,使用 hibernate 我需要在哪里显示 PDF 文件、doc 文件等。我有 webservice 的 PDF/doc 文件的字节数组,我需要将该字节数组显示为 HTML 中的 PDF 文件/doc。我使用以下代码将其转换为 pdf 并正确显示在 html 页面中

   byte[] pdf = new byte[] {}; // Load PDF byte[] into here
                if (pdf != null) {

                    // set pdf content
                    response.setContentType("application/pdf");

                    // write the content to the output stream
                    BufferedOutputStream fos1 = new BufferedOutputStream(
                        response.getOutputStream());
                    fos1.write(ba1);
                    fos1.flush();
                    fos1.close();
       }

对于 doc 文件,我从

更改 response.ContentType
   response.setContentType("application/pdf");
    to 
    response.setContentType( "application/msword" );   

但不是显示它,而是显示一个下载窗口。我该如何解决这个问题

【问题讨论】:

    标签: java html hibernate jsp


    【解决方案1】:

    试试这个:

    01 response.setContentLength(pdf.length);
    

    任何代理、防病毒或防火墙都可能猜测下载已完成。因此,请告知浏览器您希望传输多少字节。

    【讨论】:

    • @Peter Rader 它不工作,对于 pdf 它正在工作。我对 doc 文件有问题,它显示一个下载窗口而不是显示 doc 文件
    • 如果您从 microsoft.com 安装文档查看器会怎样?
    猜你喜欢
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    相关资源
    最近更新 更多