File转java.sql.Blob(照片)Struts2

 public Blob photos(File zp) {
Blob photo=null;
try {
FileInputStream fis = new FileInputStream(zp);
BufferedInputStream bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = bis.read();
while (c != -1) {
baos.write(c);
c = bis.read();
}
bis.close();
byte[] rtn= baos.toByteArray();
InputStream input=new ByteArrayInputStream(rtn);
photo = Hibernate.createBlob(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return photo;
}

FormFile转java.sql.Blob(照片)Struts1

 public Blob photos(FormFile zp) {
Blob photo = null;
if(zp !=null)
{
try {
InputStream input = zp.getInputStream();
photo = Hibernate.createBlob(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return photo;
}

获取照片struts

 public void getZp(ActionMapping mapping, ActionForm actionform, HttpServletRequest request, HttpServletResponse response)  {
Blob photo = "从数据库中返回的照片字段";
OutputStream out = null;
response.setContentType("image/jpeg");
InputStream is = null;
if(photo != null || !"".equals(photo))
{
try {
is = photo.getBinaryStream();
byte[] buffer = new byte[1024];
out = response.getOutputStream();
int length = 0;
while((length = is.read(buffer)) != -1){
out.write(buffer,0,length);
}
} catch (Exception e) {
log.error("用户没有录入照片"+e);
}finally
{
try {
out.flush();
out.close();
} catch (IOException e) {
log.error("流没有关闭"+e);
} }
}
}

jsp页面:

 <c:if test="${not empty photo}"><!-- 请求获取照片 -->
<img src="${Context}/admin/yzxx.do?method=getZp&id=${yzxx.id}" width="100" height="100" id="imageId"/>
</c:if>
<c:if test="${empty photo}"><!-- 照片为空时显示系统照片 -->
<img src="${Context}/images/default_head.jpg" width="100" height="100" id="imageId"/>
</c:if>

blob-照片转换与展示的更多相关文章

  1. 使用Canvas把照片转换成素描画

    原文:http://www.alloyteam.com/2012/07/convert-picture-to-sketch-by-canvas/ 腾讯的alloy team写的一个素描效果,挺不错的. ...

  2. Joyoshare HEIC Converter for Mac将HEIC照片转换成其他格式的方法

    如何把HEIC格式的照片转换成其JPEG,PNG,GIF他格式呢?使用Joyoshare HEIC Converter for Mac破解版就可以,Joyoshare HEIC Converter是可 ...

  3. vue 项目文件流数据格式转blob图片预览展示

    为了图片安全性,有时候上传图片后后台不会直接返回图片地址,会返回文件流的数据格式,这种格式需要处理下才能展示在页面上   // 使用axios请求上传接口 axios({ method: 'get', ...

  4. python 实用技巧:几十行代码将照片转换成素描图、随后打包成可执行文件(源码分享)

    效果展示 原始效果图 素描效果图 相关依赖包 # 超美观的打印库 from pprint import pprint # 图像处理库 from PIL import Image # 科学计算库 imp ...

  5. 如何将你拍摄的照片转换成全景图及六面体(PTGui)

    在完成全景照片的拍摄之后,接下来,我们需要的是进行全景图的拼接.全景图片分为两种类型1.立方体全景图(6面体)制作全景时通常使用该种格式 如下图 2.球形图(2:1的单张全景图片)2:1全景图宽高比例 ...

  6. base64和Blob互相转换

      1.base64转blob(二进制数据) /** * 将以base64的图片url数据转换为Blob * @param urlData 用url方式表示的base64图片数据 */ functio ...

  7. Base64转换二进制文件对象 Blob/Base64转换 File 对象

    function convertBase64UrlToBlob(urlData) { var arr = dataurl.split(','),//去掉url的头,并转换为byte type = ar ...

  8. HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换

    1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...

  9. "ORA-01460: 转换请求无法实现或不合理"及C#操作Blob总结

    class BlobDemo { private static readonly string ConnectionString = "Data Source=Tcco;User ID=sc ...

随机推荐

  1. Method and apparatus for transitioning between instruction sets in a processor

    A data processor (104) is described. The data processor (104) is capable of decoding and executing a ...

  2. gdb x查看二进制

    参考 http://blog.csdn.net/allenlinrui/article/details/5964046 (gdb) disassemble main Dump of assembler ...

  3. bug 7715339 登录失败触发 ‘row cache lock’ 等待

    Bug 7715339 - Logon failures causes "row cache lock" waits - Allow disable of logon delay ...

  4. Android-CheckBox 实现计算器

    源码下载地址:http://download.csdn.net/detail/wu20093346/7718055 使用CheckBox的OnCheckedChangeListener做事件触发,效果 ...

  5. golang 建临时文件目录以及删除

    package main import ( "fmt" "os" "path/filepath" "strings" ) ...

  6. Redis .Net客户端源码

    1.简单介绍 当前NoSql使用已经极为普遍,无论是Java生态圈,还是.net生态圈.大大小小的Web站点在追求高性能高可靠性方面,不由自主都选择了NoSQL技术作为优先考虑的方面.主流的技术有:H ...

  7. 通过Ajax进行POST提交JSON类型的数据到SpringMVC Controller的方法

    现在在做的项目用到了SpringMVC框架,需要从前端angular接收请求的JSON数据,为了测试方便,所以直接先用AJAX进行测试,不过刚开始用平时用的ajax方法,提交请求会出现415或者400 ...

  8. 从头认识java-17.4 具体解释同步(3)-对象锁

    这一章节我们接着上一章节的问题,给出一个解决方式:对象锁. 1.什么是对象锁? 对象锁是指Java为临界区synchronized(Object)语句指定的对象进行加锁,对象锁是独占排他锁. 2.什么 ...

  9. Linux常用运维命令小结

    1. 空设备文件以及标准输入输出 /dev/null 表示空设备文件 0 表示stdin标准输入 1 表示stdout标准输出 2 表示stderr标准错误 2>&1 这里有两种解释:将 ...

  10. 理解spring对事务的处理:传播性

    所谓事务传播行为就是多个事务方法相互调用时,事务如何在这些方法间传播.Spring 支持 7 种事务传播行为: PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在 ...