--------------------- Add ------------------------ to the JSP page ----------------------
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
<Base href = "<% = basepath %>">
// Download from the official website
<SCRIPT type = "text/JavaScript" src = "<% = PATH %>/CC/util/JS/ajax-pushlet-client.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Pl. _ Init ();
// Listen to the mutisend time. mutisend is defined by me.
Pl. joinlisten ('/mutisend ');
Function ondata (event ){
Try {
// Read content
VaR context = event. Get ("MSG ");
// Solve Chinese Character garbled characters
Context = decodeuricomponent (context );
If (null! = Context & "undefined "! = Context ){
// Var A = Document. getelementbyid ("contex ");
// A. innerhtml = context;
Pushinfoshowdiv (context );
}
} Catch (e ){
}
// Exit
// Pl. Leave ();
}
</SCRIPT>
-------------------------- Add to the Web. xml file
<!-- pushlet --> <servlet><servlet-name>pushlet</servlet-name><servlet-class>nl.justobjects.pushlet.servlet.Pushlet</servlet-class><load-on-startup>3</load-on-startup></servlet><servlet-mapping><servlet-name>pushlet</servlet-name><url-pattern>/pushlet.srv</url-pattern></servlet-mapping>
------------------------ Java file -----------------
// Push public void mutisend () {try {// obtain the data list <remindinfo> List = retrieve (null, null, null, null, null); string remindcontent = ""; if (null! = List & 0! = List. size () {remindcontent = List. get (0 ). getremindcontent ();} event = event. createdataevent ("/mutisend"); event. setfield ("MSG", urlencoder. encode (remindcontent + "<br/> push time:" + new date (). tolocalestring (), "UTF-8"); // fix garbled dispatcher. getinstance (). multicast (event);} catch (unsupportedencodingexception e) {// todo auto-generated catch blocke. printstacktrace ();}}
If you need to click send on the page and then push it to each client, add
Event event = event. createdataevent ("/mutisend ");
Event. setfield ("MSG", urlencoder. encode (remindcontent + "<br/> push time:" + new date (). tolocalestring (), "UTF-8"); // fix garbled
Dispatcher. getinstance (). multicast (event );
You can use these three codes.
------------ Effect -------------