pushlet推送数据到页面

来源:互联网 发布:阿里云域名市场 编辑:程序博客网 时间:2024/06/05 16:53

1后台

package test.controller;import java.io.Serializable;import java.io.UnsupportedEncodingException;import nl.justobjects.pushlet.core.Event;import nl.justobjects.pushlet.core.EventPullSource;public class HelloWorldPushlet extends EventPullSource implements Serializable {      private static final long serialVersionUID = -4378845831200885879L;        /**      * 推送时间间隔      */      protected long getSleepTime() {          return 1000;      }        /**      * 推送时所触发的方法      */      protected Event pullEvent() {          //创建事件,并制定事件的主题          Event event = Event.createDataEvent("/fxh/helloworld");          String data = "hello world,microbingbing" + System.currentTimeMillis();          try {              data=new String(data.getBytes("UTF-8"),"ISO-8859-1");          } catch (UnsupportedEncodingException e) {              e.printStackTrace();          }          event.setField("message", data);          return event;      }  }  



2sources.properties

source3=test.HelloWorldPushlet



3页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>抽取记录</title><meta http-equiv="content-type" content="text/html; charset=UTF-8"><script type="text/javascript" src="${contextPath}/main/assets/js/jquery.js"></script><script type="text/javascript" src="${contextPath}/main/assets/js/pushlet/ajax-pushlet-client.js"></script><script type="text/javascript">     // PL._init();       PL.joinListen('/fxh/helloworld');  //事件标识 在数据源中引用      function onData(event) {       console.log(event.get("message"));        }</script></head><body></body></html>































































0 0
原创粉丝点击