ie11 java 下载文件_Java中下载文件错误

采用Servlet下载文件时,我本机运行正常,能够下载,但在别人电脑上测试时,文件过大下载时后台出错,错误信息如下:

org.mortbay.jetty.EofException

at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:760)

at org.mortbay.jetty.AbstractGenerator$Output.blockForOutput(AbstractGenerator.java:548)

at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:569)

at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:910)

at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:646)

at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:577)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)

at com.eintech.projectDeclare.web.DownloadProjectPackageServlet.doGet(DownloadProjectPackageServlet.java:61)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)

at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)

at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:59)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:255)

at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)

at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)

at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)

at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)

at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

at org.mortbay.jetty.Server.handle(Server.java:324)

at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)

at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)

at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)

at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)

at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)

at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)

at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)

Caused by: java.io.IOException: 您的主机中的软件放弃了一个已建立的连接。

at sun.nio.ch.SocketDispatcher.write0(Native Method)

at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)

at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)

at sun.nio.ch.IOUtil.write(IOUtil.java:60)

at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)

at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:166)

at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:207)

at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:693)

... 28 more

下载程序源码如下:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

String filePath = req.getParameter("filePath");

if(filePath==null){

resp.getWriter().write("{success:false,errorMessage:'文件路径为空!'}");

return;

}

resp.reset();

InputStream is = null;

OutputStream os = null;

try{

String fileName = filePath.substring(filePath.lastIndexOf("/")+1);

resp.setContentType("APPLICATION/OCTET-STREAM;charset=utf8");

resp.setHeader("Content-disposition", "attachment;filename="

+ new String(fileName.getBytes("gbk"), "iso8859-1") + "");

is = new BufferedInputStream(new FileInputStream(filePath));

os = new BufferedOutputStream(resp.getOutputStream());

int len = 0;

byte [] buf = new byte[2048];

while((len=is.read(buf))>0){

os.write(buf, 0, len);

}

os.flush();

}catch (IOException e) {

e.printStackTrace();

} finally {

try {

if(is!=null){

is.close();

}

if(os!=null){

os.close();

}

}catch (IOException e) {

e.printStackTrace();

}

}

}喻敏华

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值