论坛首页 Java企业应用论坛

用OutputStream下载大文件时,下载过程中取消下载后,websphere6.0会死掉,而tomcat不会

浏览 5164 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-11-11  
用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("********************");
	}	

}
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics