Document Version 1.0
Copyright © 2012-2013 email@example.com
Server-Sent Events is a HTML5 feature which support browse to update page content automatically.
I will show a Server-Sent Events sample which get update of serve time automatically. Server side implementation is a Java Servlet running on Tomcat.
1. Create a simple web application:
2. Create a 3.X style Java Servlet "SseServer.java"
Make sure in the Servlet, set content type of response as "text/event-stream;charset=UTF-8", and NOT
just "text/event-stream". Otherwise it does not work with Chrome.
3. Create a SSE.html file
4. Deploy the Web Application
Export the Web Application as "SSE.war", and deploy it to a running Tomcat Server.
5. Try accessing the SSE.html use browser
Access the SSE.html using link http://localhost:8080/SSE/SSE.html
Your browser should shown content as below:
When every 5 seconds, there is new line shown in your browser, congratulations, you have made your first Server-Sent Events Application!