Server Sent event code not working on jelastic
<p>I am learning Server Sent events in java and for that I am using a simple example. I am using Windows 7, Java 1.7, Tomcat 7, Eclipse Indigo. I have created a servlet (SseServer.java), the code for this servlet is as follows:</p>

<pre><code>package sse; 
import java.io.IOException; &lt;br/&gt;
import java.io.PrintWriter;&lt;br/&gt;
import java.util.Date;&lt;br/&gt;

import javax.servlet.ServletException;&lt;br/&gt;
import javax.servlet.annotation.WebServlet;&lt;br/&gt;
import javax.servlet.http.HttpServlet;&lt;br/&gt;
import javax.servlet.http.HttpServletRequest;&lt;br/&gt;
import javax.servlet.http.HttpServletResponse;&lt;br/&gt;

@WebServlet("/SseServer")&lt;br/&gt;
public class SseServer extends HttpServlet {&lt;br/&gt;
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // Besides "text/event-stream;", Chrome also needs charset, otherwise
          // does not work
          // "text/event-stream;charset=UTF-8"
          response.setContentType("text/event-stream;charset=UTF-8");
          response.setHeader("Cache-Control", "no-cache");
          response.setHeader("Connection", "keep-alive");

          PrintWriter out = response.getWriter();

          while (true) {
           out.print("id: " + "ServerTime" + "\n");
           out.print("data: " + new Date().toLocaleString() + "\n\n");
           out.flush();
           // out.close(); //Do not close the writer!
           try {
            Thread.currentThread().sleep(1000);
           } catch (InterruptedException e) {
            e.printStackTrace();
           }
          }

    }

}
</code></pre>

<p>And I am displaying the results in an html, SSE.html, the code for this is as shown below:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
 &lt;h1&gt;Current Server Time  : &lt;/h1&gt;

 &lt;div id="ServerTime"&gt;&lt;/div&gt;

 &lt;script&gt;
  if (typeof (EventSource) !== "undefined") {
   var source = new EventSource("http://localhost:8080/SSE/SseServer");
   
   // http://eastern1.j.layershift.co.uk
   //var source = new EventSource("http://eastern1.j.layershift.co.uk/SSE/SseServer");
   source.onmessage = function(event) {
    document.getElementById("ServerTime").innerHTML += event.data
      + "&lt;br&gt;&lt;br&gt;";
   };
  } else {
   document.getElementById("ServerTime").innerHTML = "Sorry, your browser does not support server-sent events...";
  }
 &lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
</p>

<p>When I run this code locally after every one second I am able to see the current time. I have also checked it on several browsers like chrome, firefox etc.</p>

<p>Since this code is working fine I decided to deploy this on cloud so I chose Jelastic.com. I created a war file and deployed it on Jelastic and tried running my sample application. But when I run the application from cloud, I can only see </p>

<p>Current Server Time : </p>

<p>I do not see the time. Can someone please tell me why this is happening? Is there something I need to change in my code? If yes then can someone please advice what it should be? Or should I change some other file/settings in eclipse while creating a war file?</p>

<p>Any help is much appreciated.</p>