用OutputStream下载大文件时,下载过程中,点取消下载后,websphere6.0会死掉
而tomcat不会,可以捕捉到异常!不过异常也是null!
不知道是不是websphere本身的Bug
下面是测试的Servelet
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class DownServlet extends HttpServlet { public DownServlet() { super(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request,response); } public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = request.getParameter("path"); File file = new File(path); response.setContentType("application/x-msdownload"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "attachment;filename=xxxf.cvs"); response.setHeader("windows-Target", "_blank"); BufferedInputStream input = new BufferedInputStream(new FileInputStream(file)); try { byte buffBytes[] = new byte[1024]; int allLength = 0; System.out.println("*********************"+path); System.out.println("开始下载"); OutputStream out = response.getOutputStream(); System.out.println("获得流之前"); int read=0; while ((read=input.read(buffBytes))!=-1) { allLength += read; out.write(buffBytes, 0, read); } System.out.println("获得流之后"+allLength); out.flush(); out.close(); input.close(); System.out.println("正常关闭文件流"); } catch (IOException e) { System.out.println("取消下载"+e.getMessage()); } System.out.println("********************"); } }
1 楼
nhpm
2007-09-04
你好厉害啊!!!!