本文共 2076 字,大约阅读时间需要 6 分钟。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE html> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <head> <title>消息推送模式与内容测试</title> <meta charset="UTF-8"> <link href="style.css" rel="stylesheet"> <meta http-equiv="Pragma" content="no-cache"> <script type="text/javascript" src="<%=basePath %>js/pushlet_js/ajax-pushlet-client.js"></script> <script type="text/javascript"> var tempTrureId = ''; var stockId = ''; function onEvent(event){ document.getElementById("info").innerHTML=event.toString(); if(event.get('p_subject')=='/temperature'){ tempTrureId = event.get("p_sid"); displayTemptrueData(event.toString()); }else if(event.get('p_subject')=='/stocks/aex'){ stockId = event.get("p_sid"); displayStocksData(event.toString()); } } function displayTemptrueData(aString) { document.getElementById("displayTemptrue").value=aString; } function displayStocksData(aString) { document.getElementById("displayStocks").value=aString; } function listemTemptrue(){ PL._init(); PL.joinListen("/temperature"); } function unsubscribeTemptrue(){ PL.unsubscribe(tempTrureId); displayTemptrueData(''); } function listemStock(){ PL._init(); PL.joinListen("/stocks"); } function unsubscribeStock(){ PL.unsubscribe(stockId); displayStocksData(""); } function leave(){ PL.unsubscribe(); PL.leave(); } </script> </head> <body> <br></body> <article> <header> <h1>pushlet例子</h1> </header> </article> <article> <form> 事件显示:<textarea rows="10" cols="30" id=displayTemptrue></textarea> 天气显示:<textarea rows="10" cols="30" id=displayStocks></textarea> <input type="button" value="监听天气" οnclick="listemTemptrue();"/> <input type="button" value="取消监听天气" οnclick="unsubscribeTemptrue();"/> <input type="button" value="监听股票" οnclick="listemStock();"/> <input type="button" value="取消监听股票" οnclick="unsubscribeStock()"/> <input type="button" value="离开" οnclick="leave()"/> <div id=info style="width:400px;height:200px;border:1px solid"></div> </form> </article> </html>转载地址:http://zbyxi.baihongyu.com/