rendfile下载文件,如果文件比较大,后台会以相同参数反复多次进入同一个action,直至文件下载完
通过http链接get方法请求jfinal的rendfile下载文件,如果文件比较大,后台会以相同参数反复多次进入同一个action,直至文件下载完,因为action中有相关事务,不能重复进入,该怎么解决呢!
参考如下几个方案:
1:在去往下载页面的 action 之中,创建一个类似于 token 的东东存放在服务端一份,然后在这个下载链接上用问号挂参的方式带上来个 token,下载请求到来时,删掉服务端这份token,并开始下载过程,后来到来的请求再次使用这个 token时,服务端不进行 renderFile即可。注意处理好多线程同步问题
2:为链接添加单击事件,点击以后变为不可用,或者点击以后让 href属性变为无效,例如:
<a href="/file.zip" id="downLoad" /> // 添加一段脚本 $("#downLoad").click(function() { $(this).attr("href", "javascript:void(0)"); });
######前端动态创建连接,而且只触发了一次下载, 后端action中查询数据,生成部门分组,导出多个excel,构造zip并下载。 现在情况是触发一次下载,浏览器点保存后,反复进入action中下载######
<a href="/file.zip" id="downLoad" /> // 添加一段脚本 $("#downLoad").click(function() { this.attr("href", "javascript:void(0)"); });
即使加了token,反复被提交的action里参数出现的tonken也是一样的~ 前端动态创建连接,而且只触发了一次下载,
function downloadFileURL(url,fileName){ var aLink = document.createElement('a'); var evt = document.createEvent("HTMLEvents"); evt.initEvent("click", false, false); aLink.download = fileName; aLink.href = url; aLink.dispatchEvent(evt); }后端action中查询数据,生成部门分组,导出多个excel,构造zip并下载。 现在情况是触发一次下载,浏览器点保存后,反复进入action中下载
2016-05-12 17:15:05,235 [qtp602497195-139] ERROR [com.jfinal.core.ActionHandler] - /btwl/export_test?tab=t_art_wlqyxx&tabcn=xzcv&topjump=2&template=xd20160509.xls&sessionid=123123123&token=1463029033914 com.jfinal.render.RenderException: org.eclipse.jetty.io.EofException at com.jfinal.render.FileRender.rangeRender(FileRender.java:150) at com.jfinal.render.FileRender.render(FileRender.java:74) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:93) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:47) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:745) Caused by: org.eclipse.jetty.io.EofException at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:914) at org.eclipse.jetty.http.AbstractGenerator.blockForOutput(AbstractGenerator.java:523) at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:147) at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:107) at com.jfinal.render.FileRender.rangeRender(FileRender.java:137) ... 40 more Caused by: java.io.IOException: 您的主机中的软件中止了一个已建立的连接。 at sun.nio.ch.SocketDispatcher.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51) at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) at sun.nio.ch.IOUtil.write(IOUtil.java:51) at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487) at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:293) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:362) at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:850) ... 44 more
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。