OAF数据库动态图片的实现
2010-08-15 16:02
423 查看
将图片写入数据库:
表字段类型为BLOB,在OAF中创建对应的Item,关联到相应VO属性,Item syle 设为MessageFileUpload
提交后就会自动保存到数据库中,使用PL/SQL Developer查看图片是否存储。
读取图片并在网页中显示:
流程:获取临时文件夹物理路径---从VO读取数据---使用IO流输出图片-修改Image Item的Source属性。
获取临时文件夹物理路径(CO代码):
从VO读取数据(AM代码):
使用IO流输出图片(AM代码):
修改Image Item的Source属性(CO代码)
注解:
1.如果不需要显示图片,而只是提供下载,那么使用MessageDownload会容易得多(无需手动输出)
2.Image Item也可以用代码创建。
3.由于OAF默认的图片文件夹是在OA_MEDIA下,如果使用视图的临时变量作为Image Item的 Image URL引用,图片地址会错误
4.将图片存储于数据库中管理不易,性能也不如直接保存图片URL的好
5.生成的图片不论原格式是JPG.PNG或是GIF,统一为GIF浏览器也可以显示出来
6.此代码没有做安全处理,包括上传文件大小和文件类型
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/vslkyjnew/archive/2009/09/09/4535358.aspx
表字段类型为BLOB,在OAF中创建对应的Item,关联到相应VO属性,Item syle 设为MessageFileUpload
提交后就会自动保存到数据库中,使用PL/SQL Developer查看图片是否存储。
读取图片并在网页中显示:
流程:获取临时文件夹物理路径---从VO读取数据---使用IO流输出图片-修改Image Item的Source属性。
获取临时文件夹物理路径(CO代码):
//物理路径 String phyPath = pageContext.getTemporaryImageLocation(); //相对路径 String relPath = pageContext.getTemporaryImageSource(); /*以下两行注释用于生成唯一图片名,可视需要使用*/ //String imageName = pageContext.generateUniqueImageName("UserIcon.gif", //OAWebBeanConstants.OA_TEMPORARY_IMAGE); String imageName = "UserIcon"+user_id+".gif"; Serializable[] parameters = { user_id, phyPath, imageName }; am.invokeMethod("queryUser", parameters); //物理路径 String phyPath = pageContext.getTemporaryImageLocation(); //相对路径 String relPath = pageContext.getTemporaryImageSource(); /*以下两行注释用于生成唯一图片名,可视需要使用*/ //String imageName = pageContext.generateUniqueImageName("UserIcon.gif", //OAWebBeanConstants.OA_TEMPORARY_IMAGE); String imageName = "UserIcon"+user_id+".gif"; Serializable[] parameters = { user_id, phyPath, imageName }; am.invokeMethod("queryUser", parameters);
从VO读取数据(AM代码):
public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } } public void queryUser(String user_id, String phyPath, String imageName) { //此处调用了视图的查询方法 getUserVO1().initQuery(new Number(Integer.parseInt(user_id))); OAViewObject vo = (OAViewObject)getUserVO1(); BlobDomain image = null; if (vo.hasNext()) { Row row = vo.next(); image = (BlobDomain)row.getAttribute("Icon"); if (image != null) initImage(image, phyPath, imageName); } }
使用IO流输出图片(AM代码):
private void initImage(BlobDomain image, String phyPath, String imageName) { File directory = new File(phyPath); if (!directory.exists()) directory.mkdirs(); File imageFile = new File(directory, imageName); try { fromInputToOutput(image.getBinaryStream(), new FileOutputStream(imageFile)); } catch (Exception exception) { exception.printStackTrace(); } //DEBUG专用,看看路径对不对 System.out.println(imageFile.getAbsolutePath()); } /*复制方法,图片大可以增大byte块*/ public void fromInputToOutput(InputStream inputstream, OutputStream outputstream) throws IOException { byte abyte0[] = new byte[255]; for (int i = 255; i == 255; ) { i = inputstream.read(abyte0); if (i < 0) break; outputstream.write(abyte0, 0, i); } outputstream.close(); inputstream.close(); } private void initImage(BlobDomain image, String phyPath, String imageName) { File directory = new File(phyPath); if (!directory.exists()) directory.mkdirs(); File imageFile = new File(directory, imageName); try { fromInputToOutput(image.getBinaryStream(), new FileOutputStream(imageFile)); } catch (Exception exception) { exception.printStackTrace(); } //DEBUG专用,看看路径对不对 System.out.println(imageFile.getAbsolutePath()); } /*复制方法,图片大可以增大byte块*/ public void fromInputToOutput(InputStream inputstream, OutputStream outputstream) throws IOException { byte abyte0[] = new byte[255]; for (int i = 255; i == 255; ) { i = inputstream.read(abyte0); if (i < 0) break; outputstream.write(abyte0, 0, i); } outputstream.close(); inputstream.close(); }
修改Image Item的Source属性(CO代码)
OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);} OAImageBean image = (OAImageBean)webBean.findIndexedChildRecursive("Icon"); if (image != null) { image.setSource(relPath + imageName);}
注解:
1.如果不需要显示图片,而只是提供下载,那么使用MessageDownload会容易得多(无需手动输出)
2.Image Item也可以用代码创建。
3.由于OAF默认的图片文件夹是在OA_MEDIA下,如果使用视图的临时变量作为Image Item的 Image URL引用,图片地址会错误
4.将图片存储于数据库中管理不易,性能也不如直接保存图片URL的好
5.生成的图片不论原格式是JPG.PNG或是GIF,统一为GIF浏览器也可以显示出来
6.此代码没有做安全处理,包括上传文件大小和文件类型
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/vslkyjnew/archive/2009/09/09/4535358.aspx
相关文章推荐
- OAF数据库动态图片的实现
- OAF数据库动态图片的实现
- 利用javascript实现图片动态的放大和缩小
- Jquery实现动态切换图片的方法
- Photoshop实现修改gif格式动态图片,如切换背景颜色等.....
- 实现iOS图片等资源文件的热更新化(三):动态的资源文件夹
- FileUpload实现将图片保存到数据库在image中显示
- 在Java中利用动态代理实现数据库连接与事务的自动管理
- 详解vb.net实现图片以二进制形式上传和读取到数据库
- 数据库动态加载省市区信息,实现三级联动
- 基于JSP实现数据库中图片的存储与显示(已经通过测试)
- 关于数据库动态列呈现的实现方案---创建动态类或为Table添加TableRow
- . Net 2.0 实现动态切换首页图片···················
- java+mysql实现保存图片到数据库,以及读取数据库存储的图片
- JQuery实现图片放大的动态菜单效果
- Nginx+Lua+GraphicsMagick实现动态生成指定尺寸的图片
- php上传图片到指定位置路径保存到数据库的具体实现
- php实现将文件写入数据库、从数据库读取文件(防止图片上传漏洞)
- 用jquery实现图片的动态缩放,拖放
- 工厂+反射实现动态配置数据库