NutzCN Logo
问答 为什么在360兼容模式下通过nutz下载文件是会提交多次
发布于 2987天前 作者 qq_a1b6f073 1804 次浏览 复制 上一个帖子 下一个帖子
标签:
为什么在360兼容模式下通过nutz下载文件是会提交多次,且会报错。而firefox 及chrome都不会。
但通过原始的servlet下载,虽然会提交多次,但不会报错。
有什么办法解决?
6 回复

我也一样,这种情况在spring当中也一样会出现。
2016-01-23 10:26:52,477 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN - Error@/user/dfile :
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:413)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:438)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:426)

点击下载的时候会运行一次,然后弹出下载框的时候会运行一下,点下载又会运行一次。
  弹出下载框的时候会将输出流切断,所以报错了。不知道NUTZ怎么解决(spring似乎返回null就可以解决)

代码:
@At
@Ok("raw")
public InputStream dfile(HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("----begin upload2---");
response.setContentType("application/zip;charset=UTF-8");
response.addHeader("Content-disposition", "attachment; filename="
+ "1.ZIP");
InputStream in = null;
in = new FileInputStream(new File("g:/1.ZIP"));
return in ;
}

试试自行写流

@Ok("void")

Streams.writeAndClose(resp.getOutputStream(), in);

还是一样。
@At
@Ok("void")
public void dfile(HttpServletRequest request, HttpServletResponse response)
throws Exception {

    response.setContentType("application/zip;charset=UTF-8");
    response.addHeader("Content-disposition", "attachment; filename="
         + "1.ZIP");
    InputStream in = null;
    in = new FileInputStream(new File("g:/1.ZIP"));
    Streams.writeAndClose(response.getOutputStream(), in);
}

所以没有区别, 断流了还是会报异常,只是spring隐藏了吧

添加回复
请先登陆
回到顶部