从数据库读取图片输出到页面中
来源:互联网 发布:php中美元符号 编辑:程序博客网 时间:2024/05/18 01:14
private void getAttachementByIDAndFieldName(Connection con ,String attachTableName, String attachId,
String fieldName, HttpServletResponse resp) throws Exception {
//PreparedStatement pstmt = con.prepareStatement("select attachblob,attachname,filesize,filetype from "+attachTableName+" where attachid = ? ");
PreparedStatement pstmt = con.prepareStatement("select CONTENTS,FILE_NAME,FILE_SIZE,FILE_TYPE from "+attachTableName+" where FD_OBJECTID = ? ");
pstmt.setString(1, attachId);
ServletOutputStream out =null;
InputStream is =null;
try {
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
//设置头文件
// resp.setContentType("application/force-download");
// String disposition = "attachment;filename="+rs.getString(2);
// resp.setHeader("Content-Disposition",new String(disposition.getBytes(),"ISO_8859_1"));
// resp.setContentLength(rs.getInt(3));
resp.setContentType("image/jpeg");
resp.setContentLength(rs.getInt(3));
out = resp.getOutputStream();
oracle.sql.BLOB attachement =(oracle.sql.BLOB) rs.getBlob(1);
is = attachement.getBinaryStream();
byte[] byteBuffer = new byte[1024];
while(is.read(byteBuffer)!=-1){
out.write(byteBuffer ,0, byteBuffer.length);
}
is.close();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
throw new Exception(e.getMessage());
}finally{
pstmt.close();
try {
if(is!=null){
is.close();
}
if(out!=null){
out.close();
}
} catch (IOException e) {
}
}
}
页面:
<div><img id="pic"></img></div>
<input id="viewPic" type="button" value="预览" onclick="viewPic()"/>
function viewPic(){
alert("view2");
$("#pic")[0].src="attachmentdownload/attachmentIdentifyCardView?attachid=a779624b-0e2b-4f6c-bff2-c47caa0f1368=123&entityModelId=abc&fileName&cc.jpg&fieldName=phonto&attachId=c62a7452-41ee-4e3b-98f7-68cd5d5cd016&date="+new Date().getTime();
}
- 从数据库读取图片输出到页面中
- struts保存图片到数据库 ,从数据库中读取图片显示到页面
- 从数据库中读取二进制文件,并将图片打印到页面上
- SpringMVC从数据库中读取图片显示到JSP页面上
- SpringMVC从数据库中读取图片显示到JSP页面上
- 从数据库中读取图片显示在前台页面
- 从数据库中读取图片文件和将图片和写入到数据库中
- 将图片保存到数据库表中及从数据库表中读取图片并显示
- php插入图片到sqlite数据库中、从sqlite数据库中读取图片
- 从数据库读取图片存到本地
- .net实现图片保存到数据库和从数据库中读取图片-z
- php将图片保存到mysql数据库及从数据库中读取图片的方法源码
- php将图片保存到mysql数据库及从数据库中读取图片的方法源码
- php将图片保存到mysql数据库及从数据库中读取图片的方法源码
- 把图片保存到数据库中和从数据库中读取图片
- 把图片保存到数据库中和从数据库中读取图片--项目琐碎总结
- php将图片保存到mysql数据库及从数据库中读取图片的方法源码
- php读取图片流输出到页面图片
- OpenSSL - DES
- Windows下批量重命名
- 设计模式之解释器模式(Interpreter)
- 使用apachetop来分析apache实时日志
- iOS7 Sprite Kit 学习
- 从数据库读取图片输出到页面中
- git下添加新项目及用户
- Android emulator
- 学习数组时要注意的地方
- 数字游戏
- Strut1和Spring的整合
- 开发者必备的 6 款源码搜索引擎
- activity的生命周期
- USB无线网卡驱动移植(2)