我是靠谱客的博主 合适钢笔,这篇文章主要介绍JSP下载服务器文件的方法,现在分享给大家,希望可以做个参考。

本文实例讲述了JSP下载服务器文件的方法。分享给大家供大家参考,具体如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@page import="java.io.FileInputStream"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@page language="java" contentType="text/html; charset=UTF-8"%> <%@page import="com.ecc.emp.core.Context" %> <%@page import="java.io.File" %> <%@ include file="http://www.xxxx.com/head.jsp"%> <% boolean loadFlag = false; ServletOutputStream ou = null; FileInputStream fis = null; try{ Context context=(Context)request.getAttribute("context"); String accountFilePath = (String)context.getDataValue("accountFilePath"); //String accountFilePath ="E:/ComeBack/Acc_BOS_CM/WebContent/upload/product/1336873410414custormerStatement.txt"; //String accountFileName = (String)context.getDataValue("accountFileName"); String displayFileName = (String)context.getDataValue("displayFileName"); //String displayFileName ="custormerStatement.txt"; String fullPath =accountFilePath; response.reset(); response.setContentType("charset=UTF-8"); response.setContentType("text/HTML"); //response.setContentType("application/vnd.ms-excel"); String filename = new String(displayFileName.getBytes("gb2312"), "ISO8859-1"); response.setHeader("Content-Disposition","attachment; filename=" + filename); //解决HTTPS不能下载的问题 response.setHeader("Cache-Control","public"); ou = response.getOutputStream(); File file = new File(fullPath); fis = new FileInputStream(file); try { if (fis != null) { int filelen = fis.available(); byte a[] = new byte[filelen]; fis.read(a); ou.write(a); ou.flush(); } loadFlag=true; } catch (Exception e) { System.out.println("Excel is not exist!"); } out = pageContext.pushBody(); }catch(Exception e){ e.printStackTrace(); }finally{ try { fis.close(); ou.close(); ou = null; response.flushBuffer(); } catch (Exception e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } %>

希望本文所述对大家JSP程序设计有所帮助。

最后

以上就是合适钢笔最近收集整理的关于JSP下载服务器文件的方法的全部内容,更多相关JSP下载服务器文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(207)

评论列表共有 0 条评论

立即
投稿
返回
顶部