systemInfoSocket-init.jsp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <!-- 本页面是系统socket页面
  2. 使用方法 :在需要支持websocket消息推送的页面直接引入该页面,<-%@include file=".../common/systemInfoSocket-init.jsp->
  3. :在本页面需要配置wsServer.
  4. -->
  5. <%@ page contentType="text/html;charset=UTF-8" %>
  6. <script src="${ctxStatic}/plugin/layui/sockjs.js"></script><!-- 如果浏览器不支持socktjs,添加支持 -->
  7. <script type="text/javascript">
  8. (function() {
  9. var host = window.document.location.host;
  10. var pathName = window.document.location.pathname;
  11. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  12. var wsServer = "ws://" + host + projectName;
  13. var webSocket = null;
  14. if ('WebSocket' in window || 'MozWebSocket' in window) {
  15. webSocket = new WebSocket(wsServer+"/systemInfoSocketServer");
  16. } else {
  17. webSocket = new SockJS( wsServer+"/sockjs/systemInfoSocketServer");
  18. }
  19. webSocket.onerror = function(event) {
  20. jp.alert("websockt连接发生错误,请刷新页面重试!")
  21. };
  22. // 接收到消息的回调方法
  23. webSocket.onmessage = function(event) {
  24. var res=event.data;
  25. jp.toastr.info(res,"系统通知")
  26. jp.voice();
  27. };
  28. })(jQuery);
  29. </script>