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.








8 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
    Replies
    1. This simple code seems to work normally in JSP pages. But you can use it to push notifications to clients too!

      Delete
  4. Great Post ! HTML5 tutorial with simple and easy examples, Covering HTML5 Introduction, Semantic Elements,Attributes,Canvas,SVG,Multimedia,Video,Audio,Plug-ins,YouTube Videos, Geolocation, Drag and Drop, Local Storage, Coding Conventions / Style Guide. HTML5 Tutorial & CSS3 Tutorial.

    ReplyDelete
  5. Thank you very much for this simple but excellent post. This can be used for any event on server side and make push notification to the client I guess!

    ReplyDelete