Java servlet and server sent events

Viewed 20917

Is it possible to create a server sent event using java servlets so that a client could receive updates using:

 <script>
   var source = new EventSource('/events');
   source.onmessage = function(e) {
     document.body.innerHTML += e.data + '<br>';
   };
 </script>

All examples I have found on the web are using PHP but I would assume that it should work using Java's HTTP Servlet.

3 Answers
Related