Pushlet 实现服务端往客服端推送消息

系统页面弹出消息框,类似QQ提示框

1. java代码

package com.test.jbpm.common;

import java.io.Serializable;
import java.util.List;
import com.test.jbpm.web.action.BaseAction;
import nl.justobjects.pushlet.core.Dispatcher;
import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.Session;
import nl.justobjects.pushlet.core.SessionManager;
public class NoticePushlet extends BaseAction implements Serializable{ // 指定用户id
public void myUnicast(String user,String message) {
//必须注册ID PL.userid="hao";
if (SessionManager.getInstance().hasSession(user)) {
SessionManager.getInstance().getSessions();
Event event = Event.createDataEvent("/flowctrl/main");
event.setField("noticeKey", message);//内容不能使用中文
Dispatcher.getInstance().unicast(event, user);
} else {
//Event event = Event.createDataEvent("/jbpm_first/hao");
//event.setField("noticeKey", "The user:("+user+") not live!");
//Dispatcher.getInstance().unicast(event, this.getSession().getAttribute("code").toString());
//sDispatcher.getInstance().broadcast(event);
// Session[] sessions = SessionManager.getInstance().getSessions();
// for (Session session : sessions) {
// }
}
}
public void pushletInterface(List<String> prplflNoticeList) { Session[] sessions = SessionManager.getInstance().getSessions();
if (sessions != null && sessions.length > 0) {
for (Session session : sessions) {
String sessionId = session.getId();
String comcode = sessionId.split("->")[0];
int listLength = 0;
// for (PrplflNotice pn : prplflNoticeList) {
// if (comcode.equals(pn.getComcode())) {
// listLength = listLength + 1;
// }
// } if (listLength > 0) {
String msg = "��" + comcode + "���� " + listLength + " ��4S���뼰ʱ���������Ϣ";
Event event = Event.createDataEvent("/flowctrl/main");
event.setField("noticeKey", msg);
Dispatcher.getInstance().unicast(event, sessionId);
}
}
}
} public void myBroadcast() {
Event event = Event.createDataEvent("/flowctrl/main"); �
event.setField("noticeKey", "Broadcast msg");
Dispatcher.getInstance().broadcast(event);
}
}
2.jsp代码
需要引入ajax-pushlet-client.js
<script  type="text/javascript">
// 消息提醒用js,注册监听
var usercode = '<%=session.getAttribute("code")%>';
var timestamp=new Date().getTime();
PL.userid=usercode;
//PL.userid=usercode+"->"+timestamp;
PL.webRoot="${pageContext.request.contextPath}/";
PL._init();
PL.joinListen('/flowctrl/main');
function onData(event) {
var info=event.get("noticeKey");
openDia(info);
} function openDia(info) {
document.getElementById('messageInfo').innerHTML = info +'<BR><BR><a href="javascript:void(0);" onclick="deal()" target="page">点击处理(未处理完毕仍可点击以继续)</a>';
showDiv();
}
//消息提示使用
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,i = 0;
function showDiv(){
try{
divTop = parseInt(document.getElementById("dialog").style.top,10);
divLeft = parseInt(document.getElementById("dialog").style.left,10);
divHeight = parseInt(document.getElementById("dialog").offsetHeight,10);
divWidth = parseInt(document.getElementById("dialog").offsetWidth,10);
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("dialog").style.top = parseInt(document.body.scrollTop,10) + docHeight - divHeight;
document.getElementById("dialog").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth;
document.getElementById("dialog").style.visibility="visible";
}
catch(e){}
}
function closeDiv()
{
document.getElementById('dialog').style.visibility='hidden';
}
</script>

pushlet(QQ提示框)的更多相关文章

  1. qt之透明提示框(模拟qq) (非常漂亮)

    Qt实现类似QQ的登录失败的提示框,主要涉及窗口透明并添加关闭按钮,以及图标和信息的显示等. 直接上代码: #include "error_widget.h" ErrorWidge ...

  2. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  3. android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果

    需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果,  总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...

  4. android标题栏下面弹出提示框(一) TextView实现,带动画效果

    产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...

  5. html+css创建提示框

    看到下面的效果了吗? 本来我们站点是用下面的图片做的背景, 但是后期当更改完框中的提示内容,并且更新内容较多的时候,发现内容溢出了,如下图: 但是背景图片不能自动拉伸,还得重新做一张背景图,这样就导致 ...

  6. 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD

    原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...

  7. 利用 css 制作简单的提示框

    在网页开发中,为了提高用户体验,经常会用到一些提示框来引导用户,这里分享下一些简单的提示框的制作 1.首先类似一个长方形右上角一个关闭按钮 这里用到的主要是一些定位的知识,运用relative和abs ...

  8. 关于.NET前后台提示框的那点事

    前言 关于提示框,或多或少都用到过,提示框常见方式两种:js原生alert() 和 div模拟弹层:下面以一个常见的需求业务场景来展现提示框的那点事: 正文内容 客户:需求方: 小白:实现方(全权负责 ...

  9. Qt之等待提示框三(QLabel进行多图片切换)

    之前分享过的等待提示框有用QMovie播放gif图片实现的,也有纯代码实现的,今天再次分享另一种实现方式,如题目所示:QLabel进行图片的切换!     进行用户登录的时候,往往都需要后台线程进行用 ...

随机推荐

  1. [LeetCode]29. Divide Two Integers两数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  2. XML再深入

    XML 命名空间 XML 命名空间提供避免元素命名冲突的方法. 使用前缀来避免命名冲突 在 XML 中的命名冲突可以通过使用名称前缀从而容易地避免. 该 XML 携带某个 HTML 表格和某件家具的信 ...

  3. hdu 3255 体积并

    http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html http://blog.csdn.net/acdreamers/arti ...

  4. 前端(三大框架、Bootstrap,jQuery,自整理)

    前端,HTML(超文本标记语言),CSS(层叠样式表)和JavaScript(脚本语言) HTML,通常说的h5,其实按标准来说,HTML4的后续版本不带编号了,并保证向前的兼容性 CSS的版本3,增 ...

  5. arcgis server 10.1 发布动态图层展示海量及频繁更新的数据步骤

    Arcgis server  发布动态图层及调用动态图层 做这个动态图层功能的原由是 有一个30万的数据需要通过arcgis GP工具转成shp然后渲染加载进地图,原来的做法是遍历生成shp面要素,读 ...

  6. 全面了解 NOSQL

    NoSQL被我们用得最多的当数key-value存储,想知道为什么要有NOSQL,就首先要明白传统关系SQL: 传统关系数据库的瓶颈 传统的关系数据库具有不错的性能,高稳定型,久经历史考验,而且使用简 ...

  7. wx.grid

    wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEdit ...

  8. 【转】JavaScript 简史

    本文来自众成翻译.JavaScript 毋庸置疑是当今最重要的语言之一.Web 的兴起已经把 JavaScript 带到一个前所未有的地步.下面我们来看看 JavaScript 在其短短历史中是如何演 ...

  9. 数据库系统异常排查之DMV(转)

    来源: http://www.cnblogs.com/fygh/archive/2012/03/12.html 数据库系统异常是DBA经常要面临的情景,一名有一定从业经验的DBA,都会有自己一套故障排 ...

  10. 两种计算Java对象大小的方法

    之前想研究一下unsafe类,碰巧在网上看到了这篇文章,觉得写得很好,就转载过来.原文出处是: http://blog.csdn.net/iter_zc/article/details/4182271 ...