This is my server JSP code "Server_Date.jsp"
<%
response.setHeader("cache-control", "no-cache");
response.setContentType("text/event-stream");
out.print("data: " + (new java.util.Date()).toString() + "x\n\n");
out.flush();
%>
This my client jsp page "Client_Serverdate.jsp"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body onload="begin()">
<h1>Getting server updates</h1>
<div id="result"></div>
<script >
if(typeof(EventSource)!=="undefined")
{
var source=new EventSource("Server_Date.jsp");
source.addEventListener("message", function(event) {
document.getElementById("result").innerHTML = event.data;
}, false);
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events...";
}
</script>
</body>
</html>
Please help me this code is working fine in Mozilla Firefox, Opera but not working in Google Chrome (I was checked with 18.x and 20.x also).
It is going to server page I have checked with print statement but its not coming to the line document.getElementById("result").innerHTML = event.data;
.