JSP下載服務(wù)器文件的方法
更新時間:2015年10月21日 11:46:49 作者:Sunnery Sharp
這篇文章主要介紹了JSP下載服務(wù)器文件的方法,涉及JSP文件傳輸?shù)南嚓P(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了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 自動生成 catch 塊
e.printStackTrace();
}
}
%>
希望本文所述對大家JSP程序設(shè)計有所幫助。
相關(guān)文章
JSP中的PreparedStatement對象操作數(shù)據(jù)庫的使用教程
這篇文章主要介紹了JSP中的PreparedStatement對象操作數(shù)據(jù)庫的使用教程,文中舉了一些使用PreparedStatement預(yù)處理語句對象進行MySQL增刪查改的例子,需要的朋友可以參考下2016-04-04
關(guān)于JSP用戶登錄連接數(shù)據(jù)庫詳情
這篇文章主要介紹了關(guān)于JSP用戶登錄連接數(shù)據(jù)庫的相關(guān)資料,需要的朋友可以參考下面文章內(nèi)容2021-09-09
Spring MVC之DispatcherServlet詳解_動力節(jié)點Java學(xué)院整理
這篇文章主要介紹了Spring MVC之DispatcherServlet詳解_動力節(jié)點Java學(xué)院整理的相關(guān)資料,需要的朋友可以參考下2017-08-08
JDBCTM 指南:入門7-CallableStatement
JDBCTM 指南:入門7-CallableStatement...2006-10-10

