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. Input/output subsystem having an integrated advanced programmable interrupt controller for use in a personal computer

    A computer system is described having one or more host processors, a host chipset and an input/outpu ...

  2. [ES6] Extends class in ES6 vs ES5 subclass

    ES6 class with extends and super: class Tree { constructor(size = ', leaves = {spring: 'green', summ ...

  3. [Android] 图像各种处理系列文章合集

        这是我近期在做Android随手拍一个项目的各种网上关于图片处理的资料,曾经学过数字图像处理都是用C++写的,以下的资料个人觉得是很优秀的各种集合,还有一方面它是在线笔记,希望对大家有所帮助吧 ...

  4. 【试水CAS-4.0.3】第07节_CASclient配置单点登录

    完整版见https://jadyer.github.io/2015/07/26/sso-cas-client-login/ 本文源代码下载:http://download.csdn.net/detai ...

  5. 构建自己的AngularJS - 作用域和Digest(一)

    作用域 第一章 作用域和Digest(一) Angular作用域是简单javascript对象,因此你能够像对其它对象一样加入属性.然而,他们也有一些额外的功能:用于观測数据结构的变化.这样的观察能力 ...

  6. actionmode-ActionMode以及它的menu使用

    下图左边效果为Context Menu右边效果为ActionMode. ActionMode 其实就是替换在actionbar的位置上显示的一个控件.它跟actionbar一样,也是一种导航作用.只不 ...

  7. 14.NPM 常用命令

    转自:http://www.runoob.com/nodejs/nodejs-npm.html PM提供了很多命令,例如install和publish,使用npm help可查看所有命令. NPM提供 ...

  8. 建堆是 O(n) 的时间复杂度证明。

    建堆的复杂度先考虑满二叉树,和计算完全二叉树的建堆复杂度一样. 对满二叉树而言,第 \(i\) 层(根为第 \(0\) 层)有 \(2^i\) 个节点. 由于建堆过程自底向上,以交换作为主要操作,因此 ...

  9. InstallShield详细制作说明(三)

    八.许可协议 打开[Installation Designer]->[Behavior and Logic]->[Support Files/Billboards]面板 这里[Langua ...

  10. 创建VG

    创建VG smit mkvg Add a Volume Group Add a Scalable Volume Group   VOLUME GROUP name                    ...