From 889b26610797426a78970652b30540429ecc64f7 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Wed, 27 Apr 2016 18:06:10 +0200 Subject: [PATCH] Add websocket example --- .../web/controller/ChatController.java | 9 +- .../view/chat.jsp => resources/chat.html} | 163 +++++++++--------- 2 files changed, 81 insertions(+), 91 deletions(-) rename spring-mvc-java/src/main/webapp/{WEB-INF/view/chat.jsp => resources/chat.html} (86%) diff --git a/spring-mvc-java/src/main/java/org/baeldung/web/controller/ChatController.java b/spring-mvc-java/src/main/java/org/baeldung/web/controller/ChatController.java index 0570636752..5dcbe77cd5 100644 --- a/spring-mvc-java/src/main/java/org/baeldung/web/controller/ChatController.java +++ b/spring-mvc-java/src/main/java/org/baeldung/web/controller/ChatController.java @@ -8,19 +8,12 @@ import org.baeldung.model.OutputMessage; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; @Controller public class ChatController { - @RequestMapping(value = "/showChat", method = RequestMethod.GET) - public String displayChat() { - return "chat"; - } - @MessageMapping("/chat") - @SendTo("/topic/") + @SendTo("/topic/messages") public OutputMessage send(final Message message) throws Exception { final String time = new SimpleDateFormat("HH:mm").format(new Date()); diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/chat.jsp b/spring-mvc-java/src/main/webapp/resources/chat.html similarity index 86% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/chat.jsp rename to spring-mvc-java/src/main/webapp/resources/chat.html index 1d0d13e211..5704ac7b58 100644 --- a/spring-mvc-java/src/main/webapp/WEB-INF/view/chat.jsp +++ b/spring-mvc-java/src/main/webapp/resources/chat.html @@ -1,84 +1,81 @@ -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> - - - Chat WebSocket - - - - - - - - - - - - - -
-
- - -
-
-
- - -

-
-
- - + + + Chat WebSocket + + + + + + + + + + +
+
+ + +
+
+
+ + +

+
+
+ + \ No newline at end of file