迅雷下载文件显示名称connect reset by peer

J2EE 码拜 9年前 (2015-04-04) 1747次浏览 0个评论
 
package com.servlet;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.common.BeanHelper;

@SuppressWarnings("serial")
public class DownloadServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		String fullPath;
		String localPath = request.getParameter("path");
		String basePath = BeanHelper.getConfService().getScatter().getBasePath(); //private.xml中读取文件存放路径
		fullPath = basePath + localPath; //图片的全路径
		String fileName = localPath.substring(localPath.lastIndexOf("/") + 1);

		FileInputStream fis = null;
		OutputStream toClient = null;

		try {
			fis = new FileInputStream(fullPath);
			int i = fis.available(); // 得到文件大小
			byte data[] = new byte[i];
			fis.read(data); // 读数据
			fis.close();
			response.setContentType("multipart/form-data"); // 设置返回的文件类型
			response.setHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件头
			response.setContentLength(i);
			toClient = response.getOutputStream(); // 得到向客户端输出二进制数据的对象
			toClient.write(data); // 输出数据
			toClient.close();
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			//try中途发生异常后关闭所有IO流
			closeAllIO(toClient, fis);
		}
	}

	//关闭所有IO流
	private void closeAllIO(OutputStream toClient,FileInputStream fis) {
		try {
			if(toClient != null)
				toClient.close();
			if(fis != null) 
				fis.close();
		}catch(IOException e) {
			//iLog.error("IO关闭失败:"+e);
		}
	}
}

下载文件的servlet,用浏览器直接下载没有问题,用迅雷下载存在两个问题:
1. 会抛出connect reset by peer的异常,我知道是连接断开引起的,但是具体的不是很明白
2. 迅雷下载的时候,文件能够下载成功,但是文件名称是访问的servlet名称,就是web.xml中配置的servlet路径,我设置了HTTP头的文件名称,在迅雷是不起作用的吗?

迅雷下载文件显示名称connect reset by peer
40分
你用迅雷精简版、迅雷7都试过吗?
迅雷下载文件显示名称connect reset by peer
引用 1 楼 littlebrain4solving 的回复:

你用迅雷精简版、迅雷7都试过吗?

我用的迅雷极速版,版本也会有关系吗?


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明迅雷下载文件显示名称connect reset by peer
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!