标签:
Pushlet(一种comet 架构的实现)是基于Servlet 机制,数据从server端的Java 对象直接推送(push)到客户端浏览器的(动态)HTML 页面,而无需任何Java applet 或者插件的帮助。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <!-- $Id: web.xml,v 1.7 2005/02/21 17:21:49 justb Exp $ --> <web-app> <!-- Define the pushlet servlet --> <servlet> <servlet-name>pushlet</servlet-name> <servlet-class>nl.justobjects.pushlet.servlet.Pushlet</servlet-class> <load-on-startup>3</load-on-startup> </servlet> <!-- Define the Servlet Mappings. --> <!-- The pushlet --> <servlet-mapping> <servlet-name>pushlet</servlet-name> <url-pattern>/pushlet.srv</url-pattern> </servlet-mapping> </web-app>
package com; import nl.justobjects.pushlet.core.Event; import nl.justobjects.pushlet.core.EventPullSource; public class HelloWorldPlushlet { static public class HwPlushlet extends EventPullSource { // 休眠五秒 @Override protected long getSleepTime() { return 5000; } @Override protected Event pullEvent() { Event event = Event.createDataEvent("/cuige/he"); event.setField("mess", "hello,world!Plushlet!"); return event; } } }
source1=com.HelloWorldPlushlet$HwPlushlet
在JSP中调用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Pragma" content="no-cache" /> <script type="text/javascript" src="ajax-pushlet-client.js"></script> <script type="text/javascript"> PL._init(); PL.joinListen(‘/cuige/he‘); function onData(event) { alert(event.get("mess")); // 离开 // PL.leave(); } </script> </head> <body> <center> <h1> my first pushlet! </h1> </center> </body> </html>
标签:
原文地址:http://www.cnblogs.com/zhoumodeyoushang/p/4901807.html