public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Date start = new Date();
ServletOutputStream out = null;
FileInputStream input = null;
String sign = "";
sign = request.getParameter("sign");
BufferedOutputStream bos = null;
try {
// zip files and generate a new zip file
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\""
+ fileName + "\"");
File file = new File(path + fileName);
out = response.getOutputStream();
input = new FileInputStream(file);
bos = new BufferedOutputStream(out);
//set the length of bytes while reading or writing
byte[] buf = new byte[1024 * 100]; int size = 0;
while ((size = input.read(buf)) != -1) {
//out.write(buf, 0, size);
bos.write(buf, 0, size);
}
bos.flush(); // A
System.out.println("" + response.isCommitted()); // B
Date end = new Date(); } catch (Exception e) { }
}
1,程序实现的功能:从服务器端下载到客户端。
2,用response.getOutputStream()下载时,运行bos.flush();后在客户端弹出保存窗口,当客户没有点击保存时,文件的保存不执行。但是,程序继续进行执行下面的代码块。
在这种情况下,如何根据客户端的响应来进行判断,在进行下面的处理。
3,在解释一下,在A行的代码执行后,弹出保存窗。但是程序并不等待客户端的响应,继续执行B行的代码。!!! 请问
如何在A行的代码后根据客户的请求进行程序的控制???大师们,多谢了!!急呀!!!!
急呀!!!!
throws ServletException, IOException {
Date start = new Date();
ServletOutputStream out = null;
FileInputStream input = null;
String sign = "";
sign = request.getParameter("sign");
BufferedOutputStream bos = null;
try {
// zip files and generate a new zip file
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\""
+ fileName + "\"");
File file = new File(path + fileName);
out = response.getOutputStream();
input = new FileInputStream(file);
bos = new BufferedOutputStream(out);
//set the length of bytes while reading or writing
byte[] buf = new byte[1024 * 100]; int size = 0;
while ((size = input.read(buf)) != -1) {
//out.write(buf, 0, size);
bos.write(buf, 0, size);
}
bos.flush(); // A
System.out.println("" + response.isCommitted()); // B
Date end = new Date(); } catch (Exception e) { }
}
1,程序实现的功能:从服务器端下载到客户端。
2,用response.getOutputStream()下载时,运行bos.flush();后在客户端弹出保存窗口,当客户没有点击保存时,文件的保存不执行。但是,程序继续进行执行下面的代码块。
在这种情况下,如何根据客户端的响应来进行判断,在进行下面的处理。
3,在解释一下,在A行的代码执行后,弹出保存窗。但是程序并不等待客户端的响应,继续执行B行的代码。!!! 请问
如何在A行的代码后根据客户的请求进行程序的控制???大师们,多谢了!!急呀!!!!
急呀!!!!
解决方案 »
- 商城商品添加问题
- SMTP发mail的问题,不存在的mail地址无法校验出来吗?
- 表单提交后,如何关闭当前窗体,麻烦各位叔叔阿姨
- 比较难的问题,出现错误:java.lang.IllegalStateException: Cannot forward a response that is already commited
- 求一高难度javascript算法
- 关于webwork入门的问题(100分)
- springmvc controller做一个表单
- 向高手求助!!!jsp网页中如何用按纽读数据库,然后在同一页面上显示?
- 如何将jsp/servlet/javabean做的项目打包成*.war?
- 数据库连接错误
- 一个关于JAVABEAN的编译问题
- ◆动态创建UIComponent(高手请进)
MSN:[email protected]
有兴趣的,可以探讨一下。
MSN:[email protected]