调用的方法就是这样
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
File file= new File("c:\\trace\\2003-06-17.log");
Download.download(response,file);
}
两次下载就是,提交这个请求之后,首先出现系统中的下载提示框,如果点击保存就出现保存路径的提示框,这个没有问题,但是如果点击打开,就又出现一次系统中的下载提示框,还是问你是保存还是打开的
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
File file= new File("c:\\trace\\2003-06-17.log");
Download.download(response,file);
}
两次下载就是,提交这个请求之后,首先出现系统中的下载提示框,如果点击保存就出现保存路径的提示框,这个没有问题,但是如果点击打开,就又出现一次系统中的下载提示框,还是问你是保存还是打开的
解决方案 »
- 子类方法加@override与不加有什么区别
- 40分悬赏求助:西安公交数据
- 求高手赐教,apache+tomcat整合问题
- Spring+Struts整合开发中有关配置文件的问题
- 高手来帮忙:Tomcat5.5版本的安装版使用问题
- 谁有<JSP应用开发详解 第二版>的光盘源码? 小弟急需!!!,哪位仁兄给我发一份吧~
- 请问下 util.zip 下的crc32类有什么用
- Hibernate面试题
- weblogic 如何配置使用SSL?
- jboss3.2.1的问题
- 用cmp的话,我如果要显示10000条纪录是否要用findAl()来生成10000个bean的实例?效率??
- jb开发cmp sql异常
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
File file= new File("c:\\trace\\2003-06-17.log");
Download.download(response,file);
}
throw new FileNotFoundException();
response.setContentType("text/plain");
response.setHeader("Content-disposition","attachment; filename=" + file.getName());
另外看一下客户端的script语言是否写错了,或者做一个更简单的界面直接调用Download,我也以前碰到过类似问题,最后发现是客户端JavaScript中有问题,ie6升级之后才会有这个问题,我也不清楚为什么,语法上是没有什么问题的,反正不知道为什么他总是一下提交两次。
public class Download { public static void download(HttpServletResponse response,File file) throws IOException {
if(!file.exists())
throw new FileNotFoundException();
response.setContentType( "application/octet-stream");
response.setHeader("Content-disposition","attachment; filename=" + file.getName()); InputStream in= new FileInputStream(file); ServletOutputStream out = response.getOutputStream(); int bytesRead;
int i_length = in.available();
byte buf_1[]=new byte[i_length];
while(i_length>0){
in.read(buf_1);
out.write(buf_1);
i_length=in.available();
}
out.close();
in.close();
}
}