English 中文(简体)
在“游戏”框架内下载文件时的通知
原标题:Notification when file download completes in Play framework

Im成功地利用“游戏”1.2.4向用户提供大型双向文档下载,使用“信息”方法。

我很想知道用户何时实际完成下载。 总的来说,我知道,正如我以前所做的那样,这在某种程度上是可能的。 在我网站的旧版本中,我写了一本供双亲文件下载的短信。 一旦该信封填写了档案内容,即发出通知。 当然不是完美的,但是有益的。 在我的测试中,它确实表明用户下载文件的时间多。

在审查游乐场时,我看到游戏场。 我写了自己版本的“招标书”,因此,我可以在填写档案内容的(适用)方法完成后发出通知。

我发现的问题是,尽管我撰写了几张超量数据,但要求回答问题,因为(通过Netty?)显然使即将到来的tes客(通过Netty?)达到了第二点,尽管下载文件需要两分钟才能下载。

我不想书写习俗课,尽管我更喜欢使用1.2.4的股票交易。

任何关于如何通知何时将文件下载的结尾推向用户浏览器的想法?

问题回答

you can use ArchivedEventStream.

首先是编造一个系列的ArcivedEventStream。

public class Stream<String> extends ArchivedEventStream<String> implements Serializable{

   public Stream(int arg0) {
        super(arg0);
   }

}

then on your controller...

public static void downloadPage(){
    Stream<String> userStream = Cache.get(session.getId(),Stream.class);
    if( userStream == null){
        userStream = new Stream<String>(5);
        Cache.add(session.getId(), userStream);
    }
    render();
}

public static void download(){
    await(10000);// to provide some latency. actually no needed
    renderBinary(Play.getFile("yourfile!"));
}

public static void isDownloadFinished(){
    Stream<String> userStream = Cache.get(session.getId(),Stream.class);
    List<IndexedEvent<String>> list = await(userStream.nextEvents(0));
    renderJSON(list.get(0).data);

}

@After(only="download")
static void after(){
    Stream<String> userStream = Cache.get(session.getId(),Stream.class);
    userStream.publish("ok");
}

页: 1

#{extends  main.html  /}

#{set title: downloadPage  /}
<a href="download" target="_blank">download</a>

<script>
$(document).ready(function(){
$.ajax( /application/isDownloadFinished ,{success:function(data){
    if(data){
        console.log("downloadFinished");    
    }

}});
});

</script>

当您的下载结束时,原页将检索通知。

该法典只是一个样本。 你可以读到档案馆,自行执行。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签