websocket @ServerEndpoint注解形式开发 @OnOpen 如何获取httpSession
来源:互联网 发布:电脑服务网络怎么办 编辑:程序博客网 时间:2024/06/17 06:40
新建一个GetHttpSessionConfigurator类并继承Configurator类
import javax.servlet.http.HttpSession;import javax.websocket.HandshakeResponse;import javax.websocket.server.HandshakeRequest;import javax.websocket.server.ServerEndpointConfig;import javax.websocket.server.ServerEndpointConfig.Configurator;/* * 获取HttpSession * */public class GetHttpSessionConfigurator extends Configurator { @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(), httpSession); }}
然后在@ServerEndpoint注解里面添加configurator属性
@ServerEndpoint(value="/socketTest",configurator=GetHttpSessionConfigurator.class)
在onOpen方法里加入参数 EndpointConfig config即可获取HttpSession
@OnOpen public void onOpen(Session session,EndpointConfig config) { HttpSession httpSession= (HttpSession) config.getUserProperties().get(HttpSession.class.getName()); System.out.println( httpSession.getAttribute("name")); sessionMap.put(session.getId(), session); }
阅读全文
0 0
- websocket @ServerEndpoint注解形式开发 @OnOpen 如何获取httpSession
- websocket @ServerEndpoint注解说明
- spring websocket 获取httpsession
- WebSocket之获取HttpSession
- webSocket获取HttpSession
- webSocket获取httpSession
- WebSocket之获取HttpSession
- java WebSocket 获取httpSession
- tomcat7 @ServerEndpoint("/websocket") 404
- Tomcat下WebSocket获取HttpSession
- WebSocket中,onopen携带参数
- WebSocket获取httpSession空指针异常的解决办法
- WebSocket将httpsession作为参数
- springmvc注解形式的开发参数接收
- Controller注解形式做Spring MVC开发
- struts2 使用注解形式开发Action步骤
- axis中获取HttpSession
- 在spring3.2.0+hibernate3.3.2+struts2 2.2.3中使用websocket,运行环境是tomcat8.0.36,获取HttpSession
- 用RYU实现集线器功能
- 句柄类
- 清华大学2003年机试-球的半径和体积-1068
- 程序员编程生涯中会犯的7个错误
- [Linux] OpenSSH 升级
- websocket @ServerEndpoint注解形式开发 @OnOpen 如何获取httpSession
- java是否为空的判断的例子
- 08.js.while循环
- 来自数据库的大数据预处理Python机器学习篇(一)
- 使用 delve 调试 golang 程序
- Package.com.google.gson API 详细 学习(2)
- Linux 实用命令
- 新路程------linux内核和busybox配置ulimit使能core dump
- Stealing Harry Potter's Precious HDU