`
Sarah-Brightman
  • 浏览: 76343 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

让浏览器下载文件,而不是直接打开

阅读更多
<a href="download.jsp?filePath=<s:property value="downloadAddr"/>&fileName=<s:property value="fileName"/>">下载</a>


download.jsp的内容(全部内容):
<%	response.setContentType("application/octet-stream");
	String path = request.getParameter("filePath");
	String fileName = request.getParameter("fileName");
	response.addHeader("Content-Disposition","attachment; filename="+fileName);
	java.io.FileInputStream  fileInputStream = new java.io.FileInputStream(path);
	int i;
	while((i=fileInputStream.read())!=-1){
		out.write(i);
	}
	fileInputStream.close();
	out.close();
%>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics