An Oracle blog about Java Technology

Using Server-Sent Events (SSE) with Nothing More Than Servlet

Guest Author

As many of you know, HTML 5 Server-Sent Events (SSE) stands between the two extremes of completely stateless REST/HTTP and fully bidirectional WebSocket. It is a relatively simple mechanism that allows for sending data from the server to the client once a connection is established via plain HTTP. An interesting side-effect of this basic simplicity is you could conceivably use SSE with nothing more than the plain Servlet API. The downside of taking this approach is that you don't have the much higher level, easier to use specialized APIs for SSE such as the ones long included in Jersey (and now being proposed as part of Java EE 8).

The GlassFish team's own Shing Wai Chan explores the idea of using SSE from plain Servlets in an excellent recent post. The post is a very good way of understanding how SSE actually works under the hood. Besides demonstrating the basics of SSE from an HTTP perspective, the post also shows the JavaScript SSE API available on the browser as well as using the Servlet 3 async API and Java EE 7 concurrency utilities with Servlet based SSE.

Join the discussion

Comments ( 2 )
  • alex Sunday, July 27, 2014

    I really need to read about this, because I still can't figure out how one can "push" anything over HTTP (other than using one of the established 3 tricks).

  • Reza Rahman Sunday, July 27, 2014

    May or may not be worth it for you to look at Jersey SSE: https://blogs.oracle.com/theaquarium/entry/server_sent_events_sse_in or old school long polling frameworks like Comet (a bit unnecessary considering the momentum behind HTML 5).

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Integrated Cloud Applications & Platform Services