<%@page import="com.ebring.core.util.JawaGlobals"%><%@page import="com.ebring.core.util.JawaConstants"%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page language="java" import="java.io.*,java.net.*"%><%
//关于文件下载时采用文件流输出的方式处理:
//加上response.reset(),并且所有的%>后面不要换行,包括最后一个;
response.reset();//可以加也可以不加
//application.getRealPath("/main/mvplayer/CapSetup.msi");获取的物理路径
//想办法找到要提供下载的文件的物理路径+文件名
String filenamedownload = "/resources/mobile/recon/";
String logfile = request.getParameter("logfile");
File logDir = new File(JawaGlobals.getHomeDirectory(), "logs");
//显示给用户的下载文件名
java.io.OutputStream outp = null;
java.io.FileInputStream in = null;
try {
outp = response.getOutputStream();
in = new FileInputStream(new File(logDir,logfile));
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(logfile, "UTF-8"));
byte[] b = new byte[1024];
int i = 0;
while ((i = in.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
<!--由于jsp container在处理完成请求后会调用releasePageContet方法释放所用的PageContext object,
并且同时调用getWriter方法,由于getWriter方法与在jsp页面中使用流相关的getOutputStream方法冲突,
所以会造成这种异常,解决办法是:只需要在jsp页面的最后加上两条语句: out.clear();out=pageContext.pushBody();
即可(其中out,pageContext均为jsp内置对象!)-->
//以下两行可以解决首行出现换行而出现的流关闭异常错误
out.clear();
out = pageContext.pushBody();
} catch (Exception e) {
System.out.println("Error!");
response.setCharacterEncoding("UTF-8");
out.write("<div class='alert alert-error'>文件不存在!</div>");
e.printStackTrace();
} finally {
if (in != null) {
in.close();
in = null;
}
}
%>
//关于文件下载时采用文件流输出的方式处理:
//加上response.reset(),并且所有的%>后面不要换行,包括最后一个;
response.reset();//可以加也可以不加
//application.getRealPath("/main/mvplayer/CapSetup.msi");获取的物理路径
//想办法找到要提供下载的文件的物理路径+文件名
String filenamedownload = "/resources/mobile/recon/";
String logfile = request.getParameter("logfile");
File logDir = new File(JawaGlobals.getHomeDirectory(), "logs");
//显示给用户的下载文件名
java.io.OutputStream outp = null;
java.io.FileInputStream in = null;
try {
outp = response.getOutputStream();
in = new FileInputStream(new File(logDir,logfile));
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(logfile, "UTF-8"));
byte[] b = new byte[1024];
int i = 0;
while ((i = in.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
<!--由于jsp container在处理完成请求后会调用releasePageContet方法释放所用的PageContext object,
并且同时调用getWriter方法,由于getWriter方法与在jsp页面中使用流相关的getOutputStream方法冲突,
所以会造成这种异常,解决办法是:只需要在jsp页面的最后加上两条语句: out.clear();out=pageContext.pushBody();
即可(其中out,pageContext均为jsp内置对象!)-->
//以下两行可以解决首行出现换行而出现的流关闭异常错误
out.clear();
out = pageContext.pushBody();
} catch (Exception e) {
System.out.println("Error!");
response.setCharacterEncoding("UTF-8");
out.write("<div class='alert alert-error'>文件不存在!</div>");
e.printStackTrace();
} finally {
if (in != null) {
in.close();
in = null;
}
}
%>