如何SourceForge上的下载页面的工作? [英] How does SourceForge's download page work?
问题描述
在回答其他问题时也指出,SourceForge上的下载页面中加入一个隐藏&LT工作; IFRAME取代。但这似乎不再是这种情况...
In answers to other questions it was pointed out that SourceForge's download page worked by adding a hidden <iframe>. This does no longer seem to be the case...
如何在下载页面的当前版本中实现?我想建立,因为我认为顺丰的解决方案很优雅类似的东西。
How is the current version of the download page implemented? I'd like to build something similar because I consider SF's solution quite elegant.
好了,更多的precisely ......的确,最初的问题过于含糊。
Ok, more precisely...True, the initial "question" was too vague.
如果你去<一href="http://sourceforge.net/projects/beankeeper/files/beankeeper/2.6.2/beankeeper-2.6.2.tar.gz/download" rel="nofollow">http://sourceforge.net/projects/beankeeper/files/beankeeper/2.6.2/beankeeper-2.6.2.tar.gz/download有一个普通的旧的HTML链接,下载有问题的文件,但也有一个自动下载。延迟似乎有些2S。
If you go to http://sourceforge.net/projects/beankeeper/files/beankeeper/2.6.2/beankeeper-2.6.2.tar.gz/download there's a plain old HTML link to download the file in question but there's also an automatic download. The delay seems to be some 2s.
有人问我的特殊用例。我会回答,知道,它可能会从OP转移到一定程度。很简单:
Someone asked for my particular use case. I'll answer that knowing that it might divert from the OP to a certain extent. Very much simplified:
- 在或多或少传统的Java EE应用程序有两个Servlet
- 调度程序的Servlet它作为一个切入点UI控制器
- 在一个文档的Servlet的流PDF浏览器,它也具有内容处置=附件IE浏览器显示保存,或打开对话框
- 在打印出网页与多个输入字段和一个提交按钮
- 点击提交按钮时,
- 输入字段的值应该是在UI模型更新(和会话如需要) - >这就是调度的Servlet确实
- 创建PDF必须被触发 - >这就是该文件的Servlet确实
- more or less traditional Java EE app with two Servlets
- a dispatcher Servlet which acts as an entry point for the UI controller
- a "document Servlet" which streams PDF to the browser, it does so with content-disposition=attachment i.e. browser shows save-or-open dialog
- a print out page with a number of input fields and a submit button
- when the submit button is clicked
- the input field values should be updated in the UI model (and session where necessary) -> that's what the dispatcher Servlet does
- the creation of the PDF must be triggered -> that's what the document Servlet does
如果我采用了SF的模型中的表单提交将触发调度Servlet和重新加载当前页面(常规行为)。一旦页面重载我会以某种方式 - 右边,怎么SF做到这一点? - 导致浏览器调用文件的Servlet
If I adopted SF's model a form submit would trigger the dispatcher Servlet and reload the current page (regular behavior). Upon reload of the page I would somehow - right, how does SF do that? - cause the browser to invoke the document Servlet.
推荐答案
只是在页面加载改变窗口的位置。
Just change the window location during page load.
下面是一个 SSCCE ,只是copy'n'paste'n'run吧。
Here's an SSCCE, just copy'n'paste'n'run it.
<!doctype html> <html lang="en"> <head> <title>SO question 2222034</title> <script> window.onload = function() { setTimeout(function() { window.location = 'http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar'; }, 2000); // It's "cool" to let user wait 2 more seconds :/ } </script> </head> <body> <p>The download of jstl-1.2.jar will start shortly...</p> </body> </html>
或者,如果你需要使用POST,只需提交一个隐藏的表单:
Or if you need to use POST, just submit a hidden form:
<!doctype html> <html lang="en"> <head> <title>SO question 2222034</title> <script> window.onload = function() { setTimeout(function() { document.getElementById('downloadform').submit() }, 2000); // It's "cool" to let user wait 2 more seconds :/ } </script> </head> <body> <p>The download of jstl-1.2.jar will start shortly...</p> <form id="downloadform" action="http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar"></form> </body> </html>
这篇关于如何SourceForge上的下载页面的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!