Sunday, April 22, 2012

A small Tutorial on HTML5 Server Sent Events (Part-II) using TOMCAT server

NOTE: Please visit my previous blog post SSE-Part-I  which gives detailed information from basics.
This blog post mainly concentrates on designing SSE server side code on TOMCAT server using servlets. If you have visited my previous blog post, the server side code was implemented on WAMP server using perl script. For people who are java, j2ee and TOMCAT lovers like me should go through this.


Basic idea needed:

  1. Tomcat server
  2. SSE basics
  3. J2EE servlet concepts

Example 1:
Here i'll be using Eclipse IDE to demonstrate the examples. Make sure you have directory structure for a Dynamic web project like this:
  1. Created a package under Java resources called com.zinnia.server and placed the servlet named SendResponse.java. 
  2. index.html is the page from where the event source would be registered.
The code is as follows:

//SendResponse.java

//index.html

Go to the url http://localhost:8080/SSE_Test/index.html and see the time ticking which is actually being sent by the server.








3 comments:

  1. Thanks for the article!
    Would be better if the code is presented as actual text instead of it being captured in the screenshots as it is not possible to copy/paste text from screenshots to try out the code.

    ReplyDelete
  2. Great post! Thank you very much :)

    ReplyDelete
  3. what is this...
    this is normal data to display after every five seconds that we can do normally in jsp page

    starting loop with true and then sleeping thread for 5 sec
    if you add this code in JSP page it will work

    where is server sent event ?????????????????

    ReplyDelete