I'm trying to connect a JavaScript EventSource to a Servlet. I have the following JavaScript code:
var eventSource = new EventSource("notify?userId=123456");eventSource.onopen = function(e){ console.log("Connection Opened");};eventSource.onmessage = function(e){ console.log("Message: "+ e.data);};eventSource.onerror = function(e){ console.log("Error");};Where notify is the location of my Servlet (on the Servlet I use @WebServlet("/notify")) and ?userId=123456 is a parameter I'm trying to pass to the Servlet. In the developer console, the above code does not produce any logs. However, on the server-side I can see that the code did connect, though, whenever I try to send a message to the client the onmessage function is never hit. If I remove the parameter and do something like this:
var eventSource = new EventSource("notify");In the developer console, every few seconds I get:
Connection OpenedErrorIt seems to continuously repeat. What am I missing here?