随笔-314  评论-209  文章-0  trackbacks-0
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%
// 得到文件名字和路径
String filename = request.getParameter("filename");
String filepath = request.getSession().getServletContext().getgetRealPath("/download/excel/");
//String filepath = request.getRealPath("/download/excel/");
//读到流中
InputStream inputStream = new FileInputStream(filepath+"/"+filename);
//设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition","attachment;filename=\"" + filename + "\"");
//循环取出流中的数据
byte[] bytes = new byte[1000];
int len = inputStream.read(bytes);
while (len > 0){
 response.getOutputStream().write(bytes,0,len);
 len = inputStream.read(bytes);
}
inputStream.close();
%>
posted on 2008-11-03 17:58 xzc 阅读(381) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: