文件下载 jsp
<%@page language="java" contentType="text/html; charset=UTF-8"
import="java.io.*,java.net.* l"
pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8"); %>
<%
//查询实体得到文件全路径
String fileurl=FileUploadConstants.getPropValue("BASE_PATH")+UploadUtil.getSavePath("EDUCATION_PATH")+ File.separator+aicpaUploadInfo.getDocPath() ;
String filename=entity.getOldName() ;
//System.out.print(fileurl+" "+filename );
OutputStream output = null;
FileInputStream fis = null;
File file = new File( fileurl );
if( !file.exists() ){
response.getWriter().print ("<script language='javascript'>alert('文件不存在');this.history.go(-1);</script>");
response.getWriter().close();
}else{
try
{
response.reset();//可以加也可以不加
response.setContentType("application/x-download");//设置为下载application/x-download
String userAgent = request.getHeader("User-Agent");
boolean isIE = (userAgent != null) && (userAgent.toLowerCase().indexOf("msie") != -1);
if (isIE) {
filename = URLEncoder.encode(filename, "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
} else {
filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
}
output = response.getOutputStream();
fis = new FileInputStream(file);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0)
{
output.write(b, 0, i);
}
output.flush();
output.close();
out.clear();
out=pageContext.pushB