读取ORACLE数据库中BOLB形式数据在前端预览
在controller层获取数据库中相应的BOLB数据,并转换成Inputstream
类似代码:
@RequestMapping("/viewPDF.do")
public void viewPDF(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
response.setContentType("application/pdf");
FileInputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(new File(request.getParameter("wid")));
out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在前端js中添加响应事件
通过url直接访问controller中对应的方法,浏览器会根据具体输入流展示文件
var urL = contextPath + ' /sys/viewPDF?wid=/ '+wid;
window.open(url);