Pushlets:从Servlet发送消息给DHTML客户端浏览器
servletjsphtmlapplet
1, server-to-web client
pushletserver-to-web clientHTMLserver-side callbackmessaging
server-side callbackserverjava-appletRMICORBARMICORBAserverserverjavaworldhttp://www.javaworld.com/javaworld/javaqa/1999-04/05-rmicallback.html
appletmessageing serverTCP/IPUDPmulticastSoftWirediBusIBMMQSeriesBEAJMS
Pushlet
PushletappletHTMLHTTPservlet
Pushlet
PushletHTTP streaminghtmlHTTP
JSPservletHTML
<%
/** Start a line of JavaScript with a function call to parent frame. */
String jsFunPre = "<script language=JavaScript >parent.push('";
/** End the line of JavaScript */
String jsFunPost = "')</script> ";
int i = 1;
try {
// Every three seconds a line of JavaScript is pushed to the client
while (true) {
// Push a line of JavaScript to the client
out.print(jsFunPre+"Page "+(i++)+jsFunPost);
out.flush();
// Sleep three secs
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// Let client display exception
out.print(jsFunPre+"InterruptedException: "+e+jsFunPost);
}
}
} catch (Exception e) {
// Let client display exception
out.print(jsFunPre+"Exception: "+e+jsFunPost);
}
%>
|
<script LANGUAGE="JavaScript">
var pageStart="<HTML><HEAD></HEAD><BODY BGCOLOR=blue TEXT=white><H2>Server pushes: <P>";
var pageEnd="</H2></BODY></HTML>";
// Callback function with message from server.
// This function is called from within the hidden JSP pushlet frame
function push(content) {
// Refresh the display frame with the content received
window.frames['displayFrame'].document.writeln(pageStart+content+pageEnd);
window.frames['displayFrame'].document.close();
}
</script>
</HEAD>
<FRAMESET BORDER=0 COLS="*,0">
<!-- frame to display the content pushed by the pushlet -->
<FRAME SRC="push-js-stream-display.html" NAME="displayFrame" BORDER=0 SCROLLING=no>
<!-- Hidden frame with the pushlet that pushes lines of JavaScript-->
<FRAME SRC="push-js-stream-pusher.jsp" NAME="pushletFrame" BORDER=0 SCROLLING=no>
</FRAMESET>
|
<HTML>
<BODY BGCOLOR=black TEXT=white>
<H1>WAIT...</H1>
</BODY>
</HTML>
|
pushletservletjspJavascriptframe
PushletPublish-SubscribeObserver
- 作者: dlstone 访问统计: 516 2005年07月5日, 星期二 09:23 加入博采