日期:2014-05-16  浏览次数:20441 次

数据库文件下载

?@RequestMapping("/show")
?public void show(HttpServletRequest request, HttpServletResponse response) {
?????? Info info = (Info) request.getSession().getAttribute("info");
???????String imgId = R.get("imgId");// 图片ID
?????? BLOB blob = super.wmsDao.findZp(imgId);
?????? if (blob != null) {
???????// 得到java.sql.Blob对象后强制转换为oracle.sql.BLOB
??????????????response.setContentType("image/jpeg");
????????????? response.setHeader("Pragma", "No-cache");
????????????? response.setHeader("Cache-Control", "no-cache");
????????????? response.setDateHeader("Expires", 0);
????????????? ServletOutputStream out;
??????????????try {
????????????????????out = response.getOutputStream();
??????????????????? out.write(blob.getBytes(1, (int) blob.length()));
??????????????????? out.flush();
??????????????????? out.close();
??????????????} catch (Exception e) {
???????????????????? super.logDao.save(info, "失败!", "读取文件失败!");
???????????????????? e.printStackTrace();
????????????? }
???????}

?}