有两种获取链接文件名的方法:
第一种:从连接URL,从描述中获取
第二种:如果第一种获取不到,可以从URL地址中获取
比如这种地址:
http://book.booktxt.com/txtbuk/20130421/xuanhuan/20130421133601180.rar
要重新设置contentType,如application/octet-stream,再加一个filenamefilename="XXXXX.txt"
response.setHeader("Content-Disposition", "attachmentfilename="+filename)
怎么的下载方式、方法。你在后台设置一个,
<%
response.setContentType(fileminitype)
response.setHeader("Location",filename)
response.setHeader("Cache-Control", "max-age=" + cacheTime)
response.setHeader("Content-Disposition", "attachmentfilename=" + filename)//filename应该是编码后的(utf-8)
response.setContentLength(filelength)
OutputStream outputStream = response.getOutputStream()
InputStream inputStream = new FileInputStream(filepath)
byte[] buffer = new byte[1024]
int i = -1
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i)
}
outputStream.flush()
outputStream.close()
inputStream.close()
outputStream = null
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)