本文转自:http://htj1231825.iteye.com/blog/2206526
RemoteMessageServer 客服类
- package com.gw.medical.hospital.utils.dwr;
- import java.util.Iterator;
- import java.util.Map;
- import javax.servlet.http.HttpSession;
- import org.directwebremoting.ScriptBuffer;
- import org.directwebremoting.ScriptSession;
- import org.directwebremoting.WebContextFactory;
- import org.directwebremoting.annotations.RemoteMethod;
- import org.directwebremoting.annotations.RemoteProxy;
- @RemoteProxy(name = "RemoteMessageServer")
- public class RemoteMessageServer {
- /**
- *服务端初始化
- */
- @RemoteMethod
- public void onPageLoad() {
- getHttpSession().setAttribute("userInfo", "CustomerService1"); // 测试用,存入模拟userInfo信息
- RemoteMessageConstant.getServerList().put(getScriptSession().getId(), getScriptSession());// 存储当前客服,到在线客服列表
- }
- /**
- * 服务端发送信息
- *
- * @param message
- */
- @RemoteMethod
- public void addMessage(final String message) {
- HttpSession httpsession = getHttpSession();// 获取session
- String clientName = httpsession.getAttribute("clientName") == null ? "" : httpsession.getAttribute("clientName").toString();// 当前客户端ID
- ScriptSession session = RemoteMessageConstant.getMapList().get(clientName);// 根据clientName获取scriptSession;
- if (session != null) {
- // 发送消息
- String serverMessage=getHttpSession().getAttribute("userInfo").toString();
- serverMessage=serverMessage+":"+message;
- sendMessage(session,"receiveMessages",serverMessage);
- }
- }
- /**
- * 选择下一个客户端
- *
- * @return boolean
- */
- @RemoteMethod
- public String selectClient() {
- addMessage("本次会话结束!感谢您的咨询!");
- // 销毁上一位客户
- removeClient();
- ScriptSession sessionServer = getScriptSession();// 获取客服ScriptSsession
- HttpSession httpsession = getHttpSession();// 获取session
- Map<String, ScriptSession> userMap = RemoteMessageConstant.getMapList();// 用户在线MAP
- Iterator<String> iterator = userMap.keySet().iterator();
- String clientName = "";// 获取客户端列表中的,clientName;
- while (iterator.hasNext()) {
- // 判断当前用户是否有客服接入,如未接入,接入该客户
- String tempName = iterator.next();
- if (RemoteMessageConstant.getMappingList().get(tempName) == null) {
- clientName = tempName;
- break;
- }
- }
- ScriptSession session = userMap.get(clientName);// 根据clientName获取scriptSession;
- // 更改客户端的服务ID
- if (session != null) {
- // 调用页面JS
- sendMessage(session, "setServerName", httpsession.getAttribute("userInfo").toString());
- httpsession.setAttribute("clientName", clientName);// 存储当前客户ID
- RemoteMessageConstant.getMappingList().put(session.getId(), sessionServer);// 存储对应关系,到关系MAP
- return RemoteMessageConstant.getUserNamList().get(clientName);
- }
- return "";
- }
- /**
- * 销毁当前,服务端对应的客户端信息
- */
- public void removeClient() {
- HttpSession httpSession = getHttpSession();// 获取httpsession
- String clientName = httpSession.getAttribute("clientName") == null ? "" : httpSession.getAttribute("clientName").toString();
- RemoteMessageConstant.getMappingList().remove(clientName);// 从关系Map中,删除对应关系。
- RemoteMessageConstant.getMapList().remove(clientName);// 从用户Map中,删除该用户;
- RemoteMessageConstant.getUserNamList().remove(clientName);//从用户名列表 删除该用户名
- httpSession.removeAttribute("clientName");// 删除当前服务端的,客户ID
- }
- /**
- * 调用页面JS
- * @param scriptSession,jsName:JS方法名,message:发送的信息
- */
- public void sendMessage(ScriptSession scriptSession, String jsName, String message) {
- ScriptBuffer script = new ScriptBuffer();
- script.appendCall(jsName, message);
- scriptSession.addScript(script);
- }
- /**
- * get set
- */
- public ScriptSession getScriptSession() {
- return WebContextFactory.get().getScriptSession();
- }
- public HttpSession getHttpSession() {
- return WebContextFactory.get().getSession();
- }
- }
RemoteMessageClient 客户端
- package com.gw.medical.hospital.utils.dwr;
- import java.util.Collection;
- import java.util.Iterator;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpSession;
- import org.directwebremoting.Browser;
- import org.directwebremoting.ScriptBuffer;
- import org.directwebremoting.ScriptSession;
- import org.directwebremoting.ScriptSessionFilter;
- import org.directwebremoting.WebContextFactory;
- import org.directwebremoting.annotations.RemoteMethod;
- import org.directwebremoting.annotations.RemoteProxy;
- @RemoteProxy(name = "RemoteMessageClient")
- public class RemoteMessageClient {
- /**
- * 客户端初始化
- */
- @RemoteMethod
- public void onPageLoadClient() {
- ScriptSession scriptSession = getScriptSession();
- HttpSession httpSession = getHttpSession();
- String clientName = scriptSession.getId();// 获取seciptSessionID作为clientName
- httpSession.setAttribute("clientName", clientName);
- RemoteMessageConstant.getMapList().put(clientName, scriptSession);// 存储用户信息到在线用户列表
- RemoteMessageConstant.getUserNamList().put(clientName, "游客");
- // 服务器显示在线用户列表;
- showOnlinClient();
- DwrScriptSessionManagerUtil dssm = new DwrScriptSessionManagerUtil();
- try {
- dssm.init();
- } catch (ServletException e) {
- e.printStackTrace();
- }
- }
- /**
- * 客户端发送信息
- *
- * @param message
- */
- @RemoteMethod
- public void addMessageClient(String message) {
- HttpSession httpSession = getHttpSession();
- String clientName = httpSession.getAttribute("clientName") == null ? "" : httpSession.getAttribute("clientName").toString();// 获取当前登录客户端ID,在用户列表中查找相应客服
- String autoMessage = message;// 发送的内容
- ScriptSession scriptSession = RemoteMessageConstant.getMappingList().get(clientName);// 从对应Map中获取,当前客户端对应的服务端ScriptSession
- if (scriptSession != null) {
- String clientMessage=RemoteMessageConstant.getUserNamList().get(clientName);
- clientMessage+=":"+autoMessage;
- sendMessage(scriptSession,"receiveMessages",clientMessage);
- }
- }
- /**
- * 更改服务端在线用户列表
- */
- public void showOnlinClient() {
- Browser.withAllSessionsFiltered(new ScriptSessionFilter() {
- // 筛选scriptSession的用户,发送目标ID,是否在scriptSession中存在
- public boolean match(ScriptSession session) {
- if (RemoteMessageConstant.getServerList().get(session.getId()) != null) {
- return true;
- } else {
- return false;
- }
- }
- }, new Runnable() {
- private ScriptBuffer script = new ScriptBuffer();
- public void run() {
- // 输出内容到页面
- Iterator<String> it = RemoteMessageConstant.getMapList().keySet().iterator();
- String autoMessage = new String();
- while (it.hasNext()) {
- String key = it.next().toString();
- // 如果没有被分配客服,显示在等待列表中
- if (RemoteMessageConstant.getMappingList().get(key) == null) {
- autoMessage += RemoteMessageConstant.getUserNamList().get(key) + ";";
- }
- }
- script.appendCall("showOnlinClient", autoMessage);
- Collection<ScriptSession> sessions = Browser.getTargetSessions();
- for (ScriptSession scriptSession : sessions) {
- scriptSession.addScript(script);
- }
- }
- });
- }
- /**
- * get set
- */
- /**
- * 调用页面JS
- *
- * @param scriptSession
- * ,jsName:JS方法名,message:发送的信息
- */
- public void sendMessage(ScriptSession scriptSession, String jsName, String message) {
- ScriptBuffer script = new ScriptBuffer();
- script.appendCall(jsName, message);
- scriptSession.addScript(script);
- }
- public ScriptSession getScriptSession() {
- return WebContextFactory.get().getScriptSession();
- }
- public HttpSession getHttpSession() {
- return WebContextFactory.get().getSession();
- }
- }
DwrScriptSessionManagerUtil 监听
- package com.gw.medical.hospital.utils.dwr;
- import javax.servlet.ServletException;
- import org.directwebremoting.Container;
- import org.directwebremoting.ScriptBuffer;
- import org.directwebremoting.ScriptSession;
- import org.directwebremoting.ServerContextFactory;
- import org.directwebremoting.event.ScriptSessionEvent;
- import org.directwebremoting.event.ScriptSessionListener;
- import org.directwebremoting.extend.ScriptSessionManager;
- import org.directwebremoting.servlet.DwrServlet;
- public class DwrScriptSessionManagerUtil extends DwrServlet {
- private static final long serialVersionUID = -7504612622407420071L;
- public void init() throws ServletException {
- Container container = ServerContextFactory.get().getContainer();
- ScriptSessionManager manager = container.getBean(ScriptSessionManager.class);
- ScriptSessionListener listener = new ScriptSessionListener() {
- public void sessionCreated(ScriptSessionEvent ev) {
- }
- public void sessionDestroyed(ScriptSessionEvent ev) {
- if (RemoteMessageConstant.getMappingList().get(ev.getSession().getId()) != null) {
- ScriptSession scriptSession = RemoteMessageConstant.getMappingList().get(ev.getSession().getId());
- sendMessage(scriptSession,"receiveMessages","客户端已关闭!");
- }
- // 删除该用户的列表信息
- RemoteMessageConstant.getMapList().remove(ev.getSession().getId());
- RemoteMessageConstant.getMappingList().remove(ev.getSession().getId());
- RemoteMessageConstant.getServerList().remove(ev.getSession().getId());
- RemoteMessageConstant.getUserNamList().remove(ev.getSession().getId());
- // 更新服务端在线列表
- RemoteMessageClient rc = new RemoteMessageClient();
- rc.showOnlinClient();
- }
- };
- manager.addScriptSessionListener(listener);
- }
- /**
- * 调用页面JS
- * @param scriptSession,jsName:JS方法名,message:发送的信息
- */
- public void sendMessage(ScriptSession scriptSession, String jsName, String message) {
- ScriptBuffer script = new ScriptBuffer();
- script.appendCall(jsName, message);
- scriptSession.addScript(script);
- }
- }
RemoteMessageConstant 静态常量
- package com.gw.medical.hospital.utils.dwr;
- import java.util.HashMap;
- import java.util.Map;
- import org.directwebremoting.ScriptSession;
- public class RemoteMessageConstant {
- private static Map<String, ScriptSession> mapList = new HashMap<String, ScriptSession>();// 在线用户,Key为在线用户,Value为对应的客服,如果为空表示当前无客服接入;用户等待列表
- private static Map<String, String> userNamList = new HashMap<String, String>();// 在线用户名称
- private static Map<String, ScriptSession> mappingList = new HashMap<String, ScriptSession>();// 对应关系Map
- private static Map<String, ScriptSession> serverList = new HashMap<String, ScriptSession>();// 服务端在线列表
- /**
- * get set
- */
- public static Map<String, ScriptSession> getMapList() {
- return mapList;
- }
- public static void setMapList(Map<String, ScriptSession> mapList) {
- RemoteMessageConstant.mapList = mapList;
- }
- public static Map<String, ScriptSession> getMappingList() {
- return mappingList;
- }
- public static void setMappingList(Map<String, ScriptSession> mappingList) {
- RemoteMessageConstant.mappingList = mappingList;
- }
- public static Map<String, ScriptSession> getServerList() {
- return serverList;
- }
- public static void setServerList(Map<String, ScriptSession> serverList) {
- RemoteMessageConstant.serverList = serverList;
- }
- public static Map<String, String> getUserNamList() {
- return userNamList;
- }
- public static void setUserNamList(Map<String, String> userNamList) {
- RemoteMessageConstant.userNamList = userNamList;
- }
- }
serverMessage.jsp 客服页
- <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
- <!DOCTYPE html >
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Server</title>
- <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/themes/default/easyui.css">
- <script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"> </script>
- <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
- <script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/RemoteMessageServer.js"> </script>
- <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.8.3.min.js"> </script>
- <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.easyui.min.js"> </script>
- <script type="text/javascript">
- $(function(){
- dwr.engine.setActiveReverseAjax(true);
- dwr.engine.setNotifyServerOnPageUnload(true);
- onPageLoad();
- //对话框初始化
- $("#messageDialog").dialog({
- title:'对话框',
- width:600,
- height:550,
- closed:false,
- cache:false
- });
- });
- function sendMessage(message) {
- // 通过代理调用后台的addMessage方法发送消息
- RemoteMessageServer.addMessage(message);
- }
- // 前台接受消息的方法,由后台调用
- function receiveMessages(messages) {
- var p=$("
- ");
- $(p).append(messages);
- $("#messageContent").append(p);
- }
- //读取name值作为推送的唯一标示
- function onPageLoad(){
- // 通过代理,传入区别本页面的唯一标识符
- RemoteMessageServer.onPageLoad();
- }
- function selectClient(){
- RemoteMessageServer.selectClient({
- callback:function(clientName) {
- if(clientName=="")
- alert("选择失败!")
- else
- $("#messageContent").append("客户:"+clientName+",已成功接入!"+"<br/>");
- $("#messageDialog").dialog({title:'客户:'+clientName});
- }
- });
- }
- function showOnlinClient(str){
- $(".onlineUser").html(str);
- }
- /**
- * 页面JS
- */
- function showIcon(){
- if($("#icondiv").css("display")=="none"){
- $("#icondiv").css("display","block");
- }else{
- $("#icondiv").css("display","none");
- }
- }
- function addIcon(str){
- var img=$('<img src="<%=request.getContextPath()%>/images/dwr/'+str+'.gif"/>');
- $("#messageTextArea").append($(img));
- }
- function jsSendMessage(){
- var message=$("#messageTextArea").html();
- $("#messageContent").append("我:"+message+"<br/>");
- $("#messageTextArea").html("");
- this.sendMessage(message);
- }
- </script>
- <style type="text/css">
- #icondiv ul{
- width: 400px;
- height: 130px;
- overflow: auto;
- border: 1px solid black;
- }
- #icondiv ul li{
- float: left;
- width: 45px;
- list-style: none;
- }
- #icondiv ul li img{
- width: 40px;
- height: 40px;
- }
- </style>
- </head>
- <body>
- [align=center;]
- [url=javascript:void(0)]发送[/url]
- [/align]
- </div>
- </div>
- <div><input type="button" onclick="selectClient()" value="selectClient"/></div>
- [align=center;]
- [url=javascript:void(0)]发送[/url]
- [/align]
- </div>
- </div>
- </body>
- </html>
相关推荐
DWR(Direct Web Remoting)是一种Java技术,它允许...通过理解以上知识点,你可以有效地使用DWR实现从服务器向浏览器的消息推送功能。这个示例代码可以帮助你快速上手,同时,你可以根据实际需求对其进行调整和优化。
- **DWR 组件**:主要包括 Client、Proxy、Servlet 和 Server 等几个部分。 - **数据类型转换**:DWR 如何处理不同数据类型之间的转换,包括基本类型、复杂类型以及自定义类型。 - **DWRSERVLET 配置**:详细解释...
- **Comet**:一种实现Server Push的技术,通过对HTTP连接的长期保持来实现服务器向客户端推送数据。 - **WebSocket**:提供了全双工的通信通道,可以实现客户端和服务器之间的双向通信。 #### 六、应用实例 - ...
- **点对点 (Point-to-Point)**:发送者发送消息到队列,消费者从队列消费消息。 - **发布订阅 (Publish/Subscribe)**:发送者发送消息到主题,多个订阅者订阅同一主题接收消息。 **5. Cookie 和 Session 区别** -...
蓝桥杯嵌入式十五届模拟1代码
该数据集收录了2007-2022年中国各省份绿色税收相关数据,涵盖总税收、资源税、环境保护税、城市维护建设税、城镇土地使用税、车船税、耕地占用税、消费税、车辆购置税等指标。绿色税收是以保护环境、合理开发利用自然资源为目的,对特定行为或产品征收的税费,旨在通过经济手段引导企业减排降污,促进资源合理利用和可持续发展。数据包含全国31个省级行政区的年度统计,其中环境保护税自2018年开征后,与资源税等共同构成绿色税收体系,通过"多排多征、少排少征"机制推动企业环保改造。部分数据存在缺失值,但整体可直接用于区域绿色税制比较、环境政策效果评估等研究。
该资源为joblib-0.9.0b4.tar.gz,欢迎下载使用哦!
Android开发根据标签外框颜色决定字体颜色以及选中后的背景色,这样颜色不同,好看,有点难度,关键在于如何自定义控件
blue_concrete_powder
Android开发仿抖音底部加载进度条效果,中间往外走的进度条,关键是自定义View
【3D文件】硬件开发之3D文件打印,3D生成器,咸蛋超人3D打印文件,5款不同的3D文件免费下载,总有一款适合你,光之铸型:咸蛋超人3D觉醒计划 资源图片查看链接:https://blog.csdn.net/weixin_60324241/article/details/147260889?spm=1011.2415.3001.5331
j
基于Springboot框架实现的学生选课管理系统,包含一种角色:管理员,系统分为前台登录和后台两大模块,主要功能如下。 【前台登录】: 1. 学生登录:学生可以通过学号和密码登录系统,查看自己的选课情况、成绩等信息。 2. 教师登录:教师可以通过工号和密码登录系统,查看自己的教授课程、学生评价等信息。 【后台模块】: 1. 选课管理:管理员可以管理课程信息,包括添加、编辑、删除课程信息,设置课程容量,调整课程时间表等。 2. 教评管理:管理员可以管理学生对教师的评价,包括查看评价结果、编辑评价内容等。 3. 教评问题管理:管理员可以管理教评中的问题,包括添加、编辑、删除问题,设置问题选项等。 4. 校建管理:管理员可以管理校园建筑信息,包括添加、编辑、删除校建信息,查看校园地图等。 5. 教师管理:管理员可以管理教师信息,包括添加、编辑、删除教师信息,查看教师评价等。 6. 学生管理:管理员可以管理学生信息,包括添加、编辑、删除学生信息,查看学生选课情况等。 7. 课程管理:管理员可以管理课程信息,包括添加、编辑、删除课程信息,查看课程详情等。 8. 成绩管理:管理员可以管理学生成绩,包括录入、编辑、删除成绩,查看学生成绩单等。 9. 校园新闻:管理员可以发布校园新闻,包括添加、编辑、删除新闻,查看新闻详情等。 10. 系统管理:管理员可以管理系统的用户账号和权限,包括添加、编辑、删除用户,设置用户权限等。 二、项目技术 编程语言:Java 数据库:MySQL 项目管理工具:Maven 前端技术:HTML、Jquery、CSS、JavaScript、 后端技术:Spring、SpringMVC、MyBatis 三、运行环境 操作系统:Windows或者macOS JDK版本:最好是JDK1.8,其他版本理论上也可以 开发工具:IDEA、Ecplise
WINDOWS系统读取苹果分区的利器,支持HFS+及APFS分区。
1.通过提取docx需求文档有效标题的正文内容、表格及图片OCR结果,结合动态生成的提示词进行功能测试用例生成; 2.通过提取excel、yml或json格式的接口文档,结合提示词生成接口测试用例; 3.用例以json形式预览,支持导出为md、excel、json等格式; 4.安装部署简单,只需python环境即可,安装依赖库后即可运行; 5.需替换脚本里的api-key,模型调用阿里云百炼deepseek-r1的接口;
数据集介绍: 数据集包含五种美食图片,每种美食类型图片为1000张。
内容概要:本文详细介绍了LiteOS这一轻量级物联网操作系统,涵盖其特点、应用场景、开发环境搭建、内核机制、实战演练及进阶学习。LiteOS由华为开发,专为资源受限设备设计,具备轻量级、高效性、安全性和开放性等特点,适用于智能家居、工业自动化、智能穿戴和智能城市建设等领域。文章逐步讲解了Windows和Linux系统下搭建LiteOS开发环境的具体步骤,包括安装交叉编译器、HiSpark Studio、配置Python环境、下载并配置LiteOS SDK等。深入探讨了LiteOS内核的任务管理和内存管理机制,并通过Hello World程序展示了创建任务、编写代码、编译和烧录的完整流程。最后,介绍了SAL及socket编程,提供了丰富的学习资源,包括官方文档、技术论坛和开源代码库。 适合人群:具备一定编程基础,尤其是对物联网开发感兴趣的开发者,以及希望深入了解嵌入式操作系统原理的技术人员。 使用场景及目标:①学习如何在资源受限的设备上开发高效稳定的应用程序;②掌握LiteOS的任务管理、内存管理等核心机制;③通过实战演练和进阶学习,提高物联网设备的网络通信能力,如使用SAL及socket编程实现设备与服务器之间的TCP通信。 其他说明:本文不仅提供了理论知识,还结合具体代码示例和实际操作步骤,帮助读者更好地理解和应用LiteOS。物联网技术正处于快速发展阶段,掌握LiteOS开发技能将为开发者在智能家居、工业自动化、智能穿戴等领域提供强大的竞争力。
j
有轨装车机机行走机构设计分析.rar
该资源为h5py-3.13.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl,欢迎下载使用哦!