pdf字节流在jsp上怎么显示?
把pdf文件用字节流的方式存入了数据库,在jsp上提供显示或者下载链接,不知道怎么弄了,百度了下,用下面方式,显示pdf,但是我显示的全部是字节流乱码,麻烦帮忙看看
<%@ page contentType="text/html; charset=UTF-8" session="true" import="com.setting.action.FinancePdf,java.sql.Blob"%>
<%@ page import="java.io.OutputStream,java.sql.Blob" %>
<%
try{
byte [] buffer = FinancePdf.blobToBytes((Blob)request.getAttribute("Pdf"));
//获取字节流,将blob转化为byte
response.setContentType("application/pdf;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=test.pdf" );
OutputStream outStream = response.getOutputStream();
outStream.write(buffer, 0, buffer.length);
outStream.flush();
outStream.close();
outStream=null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch(IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}%>
--------------------编程问答--------------------
看看你存入数据库的编码格式跟你读出来展示的编码是否一致
--------------------编程问答--------------------
编码都是UTF-8,应该没问题。
补充:Java , Web 开发