file-s-d
来源:互联网 发布:最新网络销售招聘福州 编辑:程序博客网 时间:2024/05/17 03:25
jsp 上传
<form id="inputForm" name="inputForm" action="sys-notebook!save.action" method="post" target="_self" enctype="multipart/form-data"><tr><td>备忘录附件上传:</td><td><input type="file" name="file" size="60"/></td></tr></form>
jsp下载或显示图片
<tr><td class="form_label">附件:</td><td colspan="3"><!--<img src="sys-notebook!downLoadBlob.action?noteId=${noteId}"></img></td>--><a href="sys-notebook!downLoadBlob.action?noteId=${noteId}">${noteAtchName}</a></td></tr>
action要写的属性
private File file;
private String fileFileName;
set和get不能少
DAO层里面上传
/** * 保存备忘录,处理Blob 增 *@param sysNotebook *@param photo void */public void saveSysNotebook(SysNotebook sysNotebook,File file,String fileFileName,String fileContentType){FileInputStream in=null;Blob blobData=null;if(file!=null){try {in=new FileInputStream(file);blobData=Hibernate.createBlob(in);//实体注入属性值sysNotebook.setNoteAtchCont(blobData);String realFilePath = file.getAbsolutePath();//得到文件的绝对路径sysNotebook.setNoteAtchAddr(realFilePath);sysNotebook.setNoteAtchName(fileFileName);//文件名this.save(sysNotebook);} catch (IOException e) {e.printStackTrace();}}else{if(sysNotebook.getNoteId()!=null){//不改就是数据库的图片String hql="select s.noteAtchCont as noteAtchCont from SysNotebook s where noteId=?";Query query=createQuery(hql);query.setLong(0,sysNotebook.getNoteId());Blob blob=(Blob) query.uniqueResult();sysNotebook.setNoteAtchCont(blob);this.save(sysNotebook);}else{this.save(sysNotebook);}}}
下载(用猎豹浏览器会报)ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
Caused by: java.net.SocketException: Connection reset by peer: socket write error
/** * 获取备忘录,数据库查找Blob,相当于下载(待)文件 ,查blob *@param noteId void */public void getNoteFileBlob(Long noteId){BufferedInputStream input = null;//中间入的缓冲InputStream in = null;//本地数据到内存BufferedOutputStream out = null;//中间出的缓冲// hql语句查询String hql = "select noteAtchCont as noteAtchCont,noteAtchName as noteAtchName from SysNotebook where noteId=?";Query hqlQuery =this.getSession().createQuery(hql).setResultTransformer(Transformers.aliasToBean(SysNotebook.class));hqlQuery.setLong(0, noteId);SysNotebook sysNotebook=(SysNotebook) hqlQuery.uniqueResult();Blob blobfile=(Blob)sysNotebook.getNoteAtchCont();String filename=sysNotebook.getNoteAtchName();// 得到一个输出HttpServletResponse res = ServletActionContext.getResponse();//------这是关键,响应// 判断有没有照片if (blobfile != null) {try {out = new BufferedOutputStream(res.getOutputStream());in = blobfile.getBinaryStream();//----------------大字段对象得到二进制流。input = new BufferedInputStream(in);byte[] buffer = new byte[1024];int count = 0;String name = new String(filename.getBytes("UTF-8"),"ISO-8859-1"); res.setHeader("Content-Type", "application/x-download"); res.setHeader("Content-Disposition", "attachment; filename=\""+name+"\"");while ((count = input.read(buffer)) != -1) {// 表示文件的末尾out.write(buffer, 0, count);out.flush();}} catch (SQLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {try {out.close();//后用的input.close();in.close();} catch (IOException e) {e.printStackTrace();}}}}
- file-s-d
- fprintf(stderr, "error para in %s(), in file %s, line %d/n", __FUNCTION__, __FILE__, __LINE__);
- d's'f's'd
- s'd's
- s'd'f's'f's'd
- \s+(?<request_time>\d+(?:\.\d+)?)\s+ 解释
- Oracle's password file
- File's Owner是什么
- Cannot open source file: 'D:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\APPMODUL.CPP': No s
- D-S证据理论
- &((struct s *) 0)->d
- d gsg s
- %d %f %c %s
- D - Sloth's Angry
- a's'd
- d-s证据理论
- a's'd'f
- D-S证据理论
- 20121026-初次试水
- Java零零碎碎的笔记(一)
- mac下终端出现command not found现象解决
- 我想以后记着你心里都是你,再去爱别人。
- 通过request实现文件下载
- file-s-d
- VS快捷键
- Android字体简介
- 计算机类的技术文章应该去哪些方位投递宣布呢?
- JDK中的URLConnection参数详解
- KT (Kepner-Tregoe)
- 实时3D地形引擎开坑
- 对session和cookie的一些理解
- 基数排序