SourceForge的下载页面如何工作? [英] How does SourceForge's download page work?

查看:173
本文介绍了SourceForge的下载页面如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其他问题的答案中,有人指出,SourceForge的下载页面通过添加隐藏的< iframe> ;.这不再是这样的情况...



如何实现当前版本的下载页面?我想建立类似的东西,因为我认为SF的解决方案非常优雅。



好的,更确切地说...真的,最初的问题太模糊了。 / p>

如果你去 http://sourceforge.net/projects/beankeeper/files/beankeeper/2.6.2/beankeeper-2.6.2.tar.gz/download 有一个简单的旧的HTML链接下载有问题的文件,但也有一个自动下载。延迟似乎是大约2s。



有人问我的具体用例。我会回答,知道它可能从OP转移到一定程度。很简单:




  • 传统的Java EE应用程序与两个Servlet有所不同

  • 一个调度器Servlet作为UI控制器的入口点

  • 将PDF流式传输到浏览器的文档Servlet,它与content-disposition =附件一样,即浏览器显示保存或打开对话框

  • 当点击提交按钮时,带有多个输入字段和提交按钮

  • 的打印输出页


    • 应该在UI模型中更新输入字段值(需要时会话) - >这就是Servlet的调度程序

    • 创建PDF必须被触发 - >这是Servlet所做的工作




如果我采用SF的模型一个表单提交将触发调度Servlet并重新加载当前页面(常规行为)。重新加载页面后,我会不知何故 - 对,SF如何做? - 导致浏览器调用文档Servlet。

解决方案

只需在页面加载期间更改窗口位置。



这是一个 SSCCE ,只是copy'n'paste'n'run它。 p>

 <!doctype html> 
< html lang =en>
< head>
< title> SO问题2222034< / title>
< script>
window.onload = function(){
setTimeout(function(){
window.location ='http://download.java.net/maven/1/jstl/jars/jstl -1.2.jar';
},2000); //让用户等待2秒以上是酷:/
}
< / script>
< / head>
< body>
< p> jstl-1.2.jar的下载将很快开始...< / p>
< / body>
< / html>

或者如果您需要使用POST,只需提交一个隐藏的表单:

 <!doctype html> 
< html lang =en>
< head>
< title> SO问题2222034< / title>
< script>
window.onload = function(){
setTimeout(function(){
document.getElementById('downloadform')。submit()
},2000); //让用户等待2秒以上是酷:/
}
< / script>
< / head>
< body>
< p> jstl-1.2.jar的下载将很快开始...< / p>
< form id =downloadformaction =http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar>< / form>
< / body>
< / html>


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.

Ok, more precisely...True, the initial "question" was too vague.

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.

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:

  • 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

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.

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>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆