【发布时间】: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" );
但不是显示它,而是显示一个下载窗口。我该如何解决这个问题
【问题讨论】: