日期:2014-05-16 浏览次数:20414 次
?????? 前一篇 自己实现了http长连接 , 很繁琐,后来看到pushlet 好评如潮 ,就用pushlet 重写了一遍,由于? pushlet ajax api 以及 servlet 使用 get 方法来实现 ,并且对于中文有的问题 ,故 将其改为 post 方式,并对于中文两次编码 。
?
?
?
修改了 ajax api , ajax-pushlet-client.js ,改为 post 方式提交数据 ,并 在网络处状况时 通知 回调函数
?
修改 pushlet servlet , (nl\justobjects\pushlet\servlet\Pushlet.java) 使其支持 post 方式,原来只是支持post xml
首先 ext chat window 的建立: 用了 pushlet 代码就简洁多了 ,我基本上是把pushlet当作一个数据库使用的
?
使用代码 : (代码简要分析见后)
?
/*
利用pushlet 实现了 用户登录及时通知,退出及时通知,发送消息及时通知,用户单点登陆功能
*/
Ext.onReady(function () {
var chatWin = new Ext.Window({
width: 800,
height: 500,
title: 'Ext聊天窗口测试版',
renderTo: document.body,
border: false,
hidden: true,
layout: 'border',
closeAction: 'hide',
collapsible: true,
constrain: true,
iconCls: 'my-userCommentIcon',
maximizable: true,
items: [{
region: 'west',
id: 'chat-west-panel',
title: '用户面板',
split: true,
width: 170,
minSize: 100,
maxSize: 200,
collapsible: true,
constrain: true,
//margins:'0 0 0 5',
layout: 'accordion',
layoutConfig: {
animate: true
},
items: [{
items: new Ext.tree.TreePanel({
id: 'im-tree',
//rootVisible: false,
lines: false,
border: false,
dataUrl: 'chat/getUserFirst.jsp',
singleExpand: true,
selModel: new Ext.tree.MultiSelectionModel(),
root: new Ext.tree.AsyncTreeNode({
text: 'Sunrise',
id: 'SunriseIm',
//nodeType: 'async',
singleClickExpand: true,
expandable: true,
expanded: true
})
}),
title: '在线人员',
//layout:'form',
border: false,
autoScroll: true,
iconCls: 'im_list',
tools: [{
id: 'refresh',
qtip: '刷新在线信息',
// hidden:true,
handler: function (event, toolEl, panel) {
imRootNode.reload();
//reloadUser();
}
},
{
id: 'close',
qtip: '清除选定',
// hidden:true,
handler: function (event, toolEl, panel) {
Ext.getCmp('im-tree').getSelectionModel().clearSelections();
}
}]
},
{
title: 'Settings',
html: '<p>Some settings in here.</p>',
border: false,
iconCls: 'settings'
}]
},
{
region: 'center',
layout: 'border',
items: [{
region: 'center',
title: '历史记录 ',
id: 'history_panel',
autoScroll: true,
iconCls: 'my-userCommentIcon',
tools: [{
id: 'refresh',
qtip: '注意:如果长时间没有收到对方回应,试一