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