Commit d0e3467d549705fac09a0107b2d213f00af6f9e1
1 parent
ea4dd3b7
测试
Showing
2 changed files
with
7 additions
and
2 deletions
src/main/java/com/cnlive/shenhe/logging/logging.java
| 1 | 1 | package com.cnlive.shenhe.logging; |
| 2 | 2 | |
| 3 | +import org.slf4j.Logger; | |
| 4 | +import org.slf4j.LoggerFactory; | |
| 3 | 5 | import org.springframework.beans.factory.annotation.Value; |
| 4 | 6 | import org.springframework.stereotype.Controller; |
| 5 | 7 | import org.springframework.ui.Model; |
| ... | ... | @@ -16,6 +18,7 @@ import org.springframework.web.servlet.ModelAndView; |
| 16 | 18 | @Controller |
| 17 | 19 | @RequestMapping("/logging") |
| 18 | 20 | public class logging { |
| 21 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 19 | 22 | /** |
| 20 | 23 | * 端口 |
| 21 | 24 | */ |
| ... | ... | @@ -28,6 +31,7 @@ public class logging { |
| 28 | 31 | @GetMapping("/") |
| 29 | 32 | public ModelAndView logging( Model model) { |
| 30 | 33 | model.addAttribute("port", port); |
| 34 | + logger.info("port", port); | |
| 31 | 35 | return new ModelAndView("logging/logging.html"); |
| 32 | 36 | } |
| 33 | 37 | } | ... | ... |
src/main/resources/templates/logging/logging.html
| ... | ... | @@ -31,11 +31,12 @@ |
| 31 | 31 | <script th:inline="javascript"> |
| 32 | 32 | //websocket对象 |
| 33 | 33 | let websocket = null; |
| 34 | - var re=location.origin.replace("http:\\", "");//去掉http; | |
| 34 | + var re=location.origin; | |
| 35 | 35 | console.log(re); |
| 36 | + alert("ws://localhost:"+[[${port}]]+"/logging/websocket"); | |
| 36 | 37 | //判断当前浏览器是否支持WebSocket |
| 37 | 38 | if ('WebSocket' in window) { |
| 38 | - websocket = new WebSocket("ws://"+re+"/logging/websocket"); | |
| 39 | + websocket = new WebSocket("ws://localhost:"+[[${port}]]+"/logging/websocket"); | |
| 39 | 40 | } else { |
| 40 | 41 | console.error("不支持WebSocket"); |
| 41 | 42 | } | ... | ... |