zoukankan
html css js c++ java
JSP文件下载的实现
<%
@ page import
=
"
com.jstrd.htgl.common.Htglcommon
"
%>
<%
@ page import
=
"
java.net.*
"
%>
<%
String
mineType
=
"
text/plain
"
;
String
subject
=
request.getParameter(
"
subject
"
);
String
name
=
new
String
(request.getParameter(
"
name
"
).getBytes(
"
ISO8859-1
"
));
if
( subject !
=
null
)
{
Htglcommon bigText
=
new
Htglcommon();
byte
[] bts
=
bigText.selectText(subject,name);
if
( bts !
=
null
)
{
String
ext
=
bigText.docType;
if
( ext !
=
null
)
{
mineType
=
""
;
if
(
"
pdf
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/pdf
"
;
}
else
if
(
"
xls
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/vnd.ms-excel
"
;
}
else
if
(
"
doc
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/msword
"
;
}
else
if
(
"
gif
"
.equalsIgnoreCase(ext))
{
mineType
=
"
image/gif
"
;
}
else
if
(
"
jpg
"
.equalsIgnoreCase(ext))
{
mineType
=
"
image/jpeg
"
;
}
else
if
(
"
bmp
"
.equalsIgnoreCase(ext))
{
mineType
=
"
image/x-bmp
"
;
}
else
if
(
"
png
"
.equalsIgnoreCase(ext))
{
mineType
=
"
image/png
"
;
}
else
if
(
"
ppt
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/vnd.ms-powerpoint
"
;
}
else
if
(
"
txt
"
.equalsIgnoreCase(ext))
{
mineType
=
"
text/plain
"
;
}
else
if
(
"
zip
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/zip
"
;
}
else
if
(
"
rar
"
.equalsIgnoreCase(ext))
{
mineType
=
"
application/zip
"
;
}
if
( mineType.equals(
""
) )
{
mineType
=
application.getMimeType(
"
temp.
"
+
ext);
}
response.reset();
ServletOutputStream stream
=
response.getOutputStream();
//
response.addHeader(
"
Content-Disposition
"
,
"
attachment; filename=
"
+
URLEncoder.encode(bigText.docName,
"
gb2312
"
));
response.setContentType(mineType
+
"
; charset=gb2312
"
);
stream.write(bts);
stream.flush();
stream.close();
bts
=
null
;
}
}
}
%>
package
com.jstrd.htgl.common;
import
java.util.Calendar;
import
java.util.GregorianCalendar;
import
java.sql.Connection;
import
java.sql.PreparedStatement;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
com.exp.dao.DBConnection;
import
com.exp.dao.DBConnectionFactory;
import
com.exp.dao.EXPSQLException;
import
com.exp.dao.dialect.Dialect;
import
com.exp.dao.dialect.OracleDialect;
public
class
Htglcommon
{
public
transient
String docType
=
""
;
public
transient
String docName
=
""
;
public
Htglcommon()
{
}
/** */
/**
* 查询数据(正文)
*
*
@param
subject
* 数据对应主题
*
@return
如果数据不存在,则返回null
*
@throws
EXPSQLException
*/
public
byte
[] selectText(String subject,String strName)
throws
EXPSQLException
{
DBConnection dbConnection
=
this
.getDBConnection();
Connection con
=
dbConnection.getConnection();
PreparedStatement ps
=
null
;
ResultSet rs
=
null
;
String strString
=
""
;
try
{
Dialect dialect
=
dbConnection.getDialect();
if
(dialect
instanceof
OracleDialect)
{
ps
=
con.prepareStatement(
"
select file_body,file_name from sys_file f,flow_inst s where f.flow_inid=s.flow_inid and f.file_name=s.doc_name and f.flow_inid=? and f.file_name=?
"
);
ps.setString(
1
, subject);
ps.setString(
2
, strName);
rs
=
ps.executeQuery();
if
(rs.next())
{
byte
[] bts
=
rs.getBytes(
1
);
//
Blob blob = rs.getBytes(1);
strString
=
rs.getString(
2
);
this
.docName
=
strString;
this
.docType
=
strString.substring(strString.lastIndexOf(
"
.
"
)
+
1
);
//
byte[] bts = blob.getBytes((long) 1, (int) blob.length());
rs.close();
ps.close();
return
bts;
}
rs.close();
ps.close();
}
else
{
ps
=
con.prepareStatement(
"
select file_body,file_name from sys_file f,flow_inst s where f.flow_inid=s.flow_inid and f.file_name=s.doc_name and f.flow_inid=? and f.file_name=?
"
);
ps.setString(
1
, subject);
ps.setString(
2
, strName);
rs
=
ps.executeQuery();
if
(rs.next())
{
byte
[] bts
=
rs.getBytes(
1
);
strString
=
rs.getString(
2
);
this
.docName
=
strString;
this
.docType
=
strString.substring(strString.lastIndexOf(
"
.
"
)
+
1
);
rs.close();
ps.close();
return
bts;
}
rs.close();
ps.close();
}
return
null
;
}
catch
(SQLException sqlE)
{
throw
new
EXPSQLException(sqlE);
}
finally
{
dbConnection.close();
}
}
protected
DBConnection getDBConnection()
throws
EXPSQLException
{
return
DBConnectionFactory
.createDBConnection(
"
WorkFlow
"
);
}
}
查看全文
相关阅读:
解决在macOS下安装了python却没有pip命令的问题【经验总结】
Mac OS下安装MongoDB以及配置方法总结【笔记】
web上常见的攻击方式及简单的防御方法
Destoon二开必看执行流程
网站入侵注入的几种方法总结【笔记】
命令检测站点是否使用CDN加速
织梦xss通杀所有版本漏洞【学习笔记】
让你知晓内容安全的边界:盘点2017、2018这两年的内容监管
知物由学 | AI网络安全实战:生成对抗网络
人工智能热门图书(深度学习、TensorFlow)免费送!
原文地址:https://www.cnblogs.com/ding0910/p/646338.html
最新文章
npm太慢, 淘宝npm镜像使用方法
git 本地分支与远程分支
/etc/fstab 文件挂载配置文件
linux对4T硬盘进行分区
Linux安装npm并打包前端代码
npm 更新版本
XenServer中虚拟机和快照导出与导入
nginx跨域的简单应用
mysql 遍历所有的库并根据表和sql语句备份
win10 同步批处理禁用和启用网卡
热门文章
结构体内存对齐
编辑中常用命令
指针与内存的分配
结构体,共用体,枚举
CSS选择器
VS中代码覆盖问题
C++的string类
CSS初了解
2. getline()和get()
第一章 C++基本认识
Copyright © 2011-2022 走看看