SERVER SENT EVENTS
Examples: Facebook/Twitter updates, stock price updates, news feeds, sport results, etc.
Browser
|
Supported
|
Notes
|
---|---|---|
NO
|
[3]
| |
Yes
|
Starting with Firefox 6.0 [4]
| |
Yes
| ||
Yes
|
Starting with Opera 11 [3]
| |
Yes
|
Starting with Safari 5.0 [3]
| |
SERVER SENT EVENTS IN SPRING MVC
Controller for mapping events
@Controller @RequestMapping("sseTest.htm") public class SseController { @RequestMapping(method = RequestMethod.GET) public @ResponseBody String sendMessage(HttpServletResponse response) { Random r = new Random(); response.setContentType("text/event-stream, charset=UTF-8"); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } return "data:Testing 1,2,3" + r.nextInt() +"\n\n" + "retry: 100\n" ; } }
Controller for mapping jsp page
@Controller @RequestMapping("viewSSE.htm") public class ViewSSEController { @RequestMapping(method = RequestMethod.GET) public String home(ModelMap model){ return "viewSSE"; } }
No comments:
Post a Comment