从服务器上下载excel
来源:互联网 发布:日语语法书推荐 知乎 编辑:程序博客网 时间:2024/05/19 23:10
/**下载trs文件*/
public Object downloadtrsfile(final Integer id, final HttpServletResponse response) {
return getHibernateTemplate().execute(new HibernateCallback<Integer>(){
@Override
public Integer doInHibernate(Session session)
throws HibernateException, SQLException {
BufferedOutputStream output = null;
BufferedInputStream input = null;
try {
ServletOutputStream ops;
ops = response.getOutputStream();
String SQL="select FILE_NAME,TYPE,contractFile from TRS_FILES where id=:id";
Query q = session.createSQLQuery(SQL).setParameter("id", id);
List<?> t=q.list();
Object object=t.size()>0?t.get(0):null;
if(object!=null){
boolean isInline = true; // 是否允许直接在浏览器内打开(如果浏览器能够预览此文件内容,
String inlineType = isInline ? "inline" : "attachment"; // 是否内联附件
System.out.println(inlineType);
Object[] obs=(Object[]) object;
String name=(String) obs[0];
if(name==null||name.isEmpty()){
name="unname";
}
String downFileName = new String(name.getBytes("GBK"),"iso8859-1");
response.setHeader("Content-Disposition", inlineType+";filename=\""+downFileName+"\"");
String type=(String) obs[1];
response.setContentType(type);
Object o=obs[2];
Blob blob=(Blob)o;
InputStream bs = blob.getBinaryStream();
byte[] buffer = new byte[4096]; // 缓冲区
output = new BufferedOutputStream(ops);
input = new BufferedInputStream(bs);
int n = (-1);
while ((n = input.read(buffer, 0, 4096)) > -1) {
output.write(buffer, 0, n);
}
output.flush();
}
}catch (Exception e) {
}
finally{
try {
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
});
}
public Object downloadtrsfile(final Integer id, final HttpServletResponse response) {
return getHibernateTemplate().execute(new HibernateCallback<Integer>(){
@Override
public Integer doInHibernate(Session session)
throws HibernateException, SQLException {
BufferedOutputStream output = null;
BufferedInputStream input = null;
try {
ServletOutputStream ops;
ops = response.getOutputStream();
String SQL="select FILE_NAME,TYPE,contractFile from TRS_FILES where id=:id";
Query q = session.createSQLQuery(SQL).setParameter("id", id);
List<?> t=q.list();
Object object=t.size()>0?t.get(0):null;
if(object!=null){
boolean isInline = true; // 是否允许直接在浏览器内打开(如果浏览器能够预览此文件内容,
String inlineType = isInline ? "inline" : "attachment"; // 是否内联附件
System.out.println(inlineType);
Object[] obs=(Object[]) object;
String name=(String) obs[0];
if(name==null||name.isEmpty()){
name="unname";
}
String downFileName = new String(name.getBytes("GBK"),"iso8859-1");
response.setHeader("Content-Disposition", inlineType+";filename=\""+downFileName+"\"");
String type=(String) obs[1];
response.setContentType(type);
Object o=obs[2];
Blob blob=(Blob)o;
InputStream bs = blob.getBinaryStream();
byte[] buffer = new byte[4096]; // 缓冲区
output = new BufferedOutputStream(ops);
input = new BufferedInputStream(bs);
int n = (-1);
while ((n = input.read(buffer, 0, 4096)) > -1) {
output.write(buffer, 0, n);
}
output.flush();
}
}catch (Exception e) {
}
finally{
try {
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
});
}
- 从服务器上下载excel
- 从服务器上下载excel
- 从服务器下载Excel文件的示例
- socket实现从http服务器上下载
- 如何从linux服务器上下载文档
- svn从服务器上下载代码
- linux操作系统从服务器上下载&上传
- 从服务器上下载压缩包
- C# 从服务器下载文件代码 以excel为例
- Java表格数据导出EXCEL 并从服务器下载实例
- Excel 从ASP.NET 服务器下载到 本地
- 浏览器下载服务器上的文件(EXCEL)
- 从服务器上导出excel文件到本地
- 从其他服务器上下载数据.通过webclient
- 关于android从服务器上下载视频的问题
- android 从服务器上获取APK下载安装
- php:从服务器上下载&保存一个远程图片
- java web 从服务器上下载图片资料
- Mongodb基础用法及查询操作
- 缩略语字符串翻译为日常用语字符串的实现
- openGL及GLSL的小知识
- 从服务器上下载excel
- ibatiS和hibernate的区别
- 从服务器上下载excel
- c/c++笔试题(3)
- ubuntu debian 设置locale和时区
- Android 获取系统应用信息
- Oracle Clusterware 工具集(2)——应用层!
- 黑马程序员-java学习5
- 班级排名
- php将汉字转换为拼音和得到词语首字母
- SQLSERVER2005 死锁问题解决