JSP下載服務(wù)器文件的方法
本文實(shí)例講述了JSP下載服務(wù)器文件的方法。分享給大家供大家參考,具體如下:
<%@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 自動(dòng)生成 catch 塊 e.printStackTrace(); } } %>
希望本文所述對(duì)大家JSP程序設(shè)計(jì)有所幫助。
- JSP實(shí)現(xiàn)遠(yuǎn)程文件下載保存到服務(wù)器指定目錄中的方法
- jsp實(shí)現(xiàn)從服務(wù)器下載xls文件到客戶端的方法
- jsp實(shí)現(xiàn)Servlet文件下載的方法
- JSP文件下載功能的4種方法
- JSP response對(duì)象實(shí)現(xiàn)文件下載的兩種方式
- jsp實(shí)現(xiàn)文件上傳下載的程序示例
- jsp 文件下載示例代碼
- jsp文件上傳與下載實(shí)例代碼
- Jsp頁面實(shí)現(xiàn)文件上傳下載類代碼
- 用JSP下載word文件(不會(huì)直接用IE打開)
- JSP實(shí)現(xiàn)從不同服務(wù)器上下載文件的方法
相關(guān)文章
jsp實(shí)現(xiàn)簡(jiǎn)單圖片驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了jsp實(shí)現(xiàn)簡(jiǎn)單圖片驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02JSP 重置按鈕清空傳入的表單數(shù)據(jù)實(shí)例
本例講解的是表單清空,jquery實(shí)現(xiàn)清空表單中填寫及傳入的值,很實(shí)用,喜歡的朋友可以學(xué)習(xí)下2014-09-09JSP中的PreparedStatement對(duì)象操作數(shù)據(jù)庫的使用教程
這篇文章主要介紹了JSP中的PreparedStatement對(duì)象操作數(shù)據(jù)庫的使用教程,文中舉了一些使用PreparedStatement預(yù)處理語句對(duì)象進(jìn)行MySQL增刪查改的例子,需要的朋友可以參考下2016-04-04關(guān)于JSP用戶登錄連接數(shù)據(jù)庫詳情
這篇文章主要介紹了關(guān)于JSP用戶登錄連接數(shù)據(jù)庫的相關(guān)資料,需要的朋友可以參考下面文章內(nèi)容2021-09-09Spring MVC之DispatcherServlet詳解_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了Spring MVC之DispatcherServlet詳解_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理的相關(guān)資料,需要的朋友可以參考下2017-08-08JDBCTM 指南:入門7-CallableStatement
JDBCTM 指南:入門7-CallableStatement...2006-10-10