資源簡介
spring mvc的websocket使用實(shí)例(實(shí)現(xiàn)服務(wù)器向登錄客戶端推送消息)
maven項(xiàng)目
使用方法見內(nèi)部使用說明

代碼片段和文件信息
package?com.jyl.controller;
import?javax.servlet.http.HttpSession;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.PathVariable;
import?org.springframework.web.bind.annotation.RequestMapping;
import?org.springframework.web.bind.annotation.ResponseBody;
import?org.springframework.web.socket.TextMessage;
import?com.jyl.ws.MyHandler;
@Controller
public?class?JylController?{
@Autowired
????MyHandler?handler;
????@RequestMapping(“/login/{username}“)
????public?String??login(HttpSession?session?@PathVariable(“username“)?String?username)?{
????????session.setAttribute(MyHandler.CLIENT_ID?username);
????????System.out.println(“登錄:“?+?session.getAttribute(MyHandler.CLIENT_ID));
??????? return?“jyl“;
????}
????@RequestMapping(“/msg/{username}/{msg}“)
????public?@ResponseBody?String?sendMessage(@PathVariable(“username“)?String?username@PathVariable(“msg“)?String?msg)?{??? ???
????????handler.sendMessageToUser(username?new?TextMessage(msg));
????????return?““;
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-02-24?03:04??websocketDemo\
?????目錄???????????0??2019-02-24?02:59??websocketDemo\jyl\
?????文件????????1798??2019-02-24?02:47??websocketDemo\jyl\pom.xm
?????目錄???????????0??2018-07-16?02:06??websocketDemo\jyl\src\
?????目錄???????????0??2019-02-24?01:16??websocketDemo\jyl\src\main\
?????目錄???????????0??2019-02-24?01:33??websocketDemo\jyl\src\main\java\
?????目錄???????????0??2019-02-24?02:41??websocketDemo\jyl\src\main\java\com\
?????目錄???????????0??2019-02-24?02:04??websocketDemo\jyl\src\main\java\com\jyl\
?????目錄???????????0??2019-02-24?01:04??websocketDemo\jyl\src\main\java\com\jyl\controller\
?????文件????????1132??2019-02-24?02:48??websocketDemo\jyl\src\main\java\com\jyl\controller\JylController.java
?????目錄???????????0??2019-02-23?23:41??websocketDemo\jyl\src\main\java\com\jyl\ws\
?????文件????????3433??2019-02-24?02:48??websocketDemo\jyl\src\main\java\com\jyl\ws\MyHandler.java
?????文件?????????856??2019-02-24?02:49??websocketDemo\jyl\src\main\java\com\jyl\ws\WebSocketConfig.java
?????文件????????1254??2019-02-24?02:49??websocketDemo\jyl\src\main\java\com\jyl\ws\WebSocketInterceptor.java
?????目錄???????????0??2019-02-24?02:51??websocketDemo\jyl\src\main\webapp\
?????文件???????????2??2019-02-24?00:41??websocketDemo\jyl\src\main\webapp\index.jsp
?????目錄???????????0??2019-02-24?02:51??websocketDemo\jyl\src\main\webapp\WEB-INF\
?????文件????????1023??2019-02-24?02:48??websocketDemo\jyl\src\main\webapp\WEB-INF\applicationContext.xm
?????目錄???????????0??2019-02-24?01:04??websocketDemo\jyl\src\main\webapp\WEB-INF\jsp\
?????文件?????????610??2019-02-24?02:48??websocketDemo\jyl\src\main\webapp\WEB-INF\jsp\jyl.jsp
?????文件????????1136??2019-02-24?02:48??websocketDemo\jyl\src\main\webapp\WEB-INF\spring-servlet.xm
?????文件?????????642??2018-07-16?20:33??websocketDemo\jyl\src\main\webapp\WEB-INF\web.xm
?????目錄???????????0??2018-07-16?02:06??websocketDemo\jyl\src\test\
?????目錄???????????0??2018-07-15?18:40??websocketDemo\jyl\src\test\java\
?????文件?????????218??2019-02-24?03:08??websocketDemo\使用說明.txt
- 上一篇:Qt寫的天氣預(yù)報(bào)
- 下一篇:dijkstra算法R語言
評論
共有 條評論