我正在使用 angular 4 和 java 开发一个网络应用程序。我正在使用服务器发送的事件将一些文本数据发送到前端。在后端我使用 Jersey ,这是我的后端代码
eventOutput.write(new OutboundEvent.Builder()
.id(decodedToken)
.name("responseBody")
.data(String.class, respBody.toString()).build());
前端我使用的是 angular 4,代码看起来像
var evtSource = new EventSource("url");
source.addEventListener('eventName', (event) => {
console.log(event);
});
在 Mozilla firefox 中一切正常。当我将 chrome 与 tomcat 和 windows 一起使用时,一切正常。但是使用 tomcat+linux 和 chrome,我在控制台中看到错误。as
EventSource's response has a charset ("iso-8859-1") that is not UTF-8. Aborting the connection.
可能是什么问题。解决方法是什么?请帮忙。任何帮助,将不胜感激。谢谢。
最佳答案
Tomcat 默认支持字符集:iso-8859-1。请尝试
@Produces("application/json;charset=UTF-8")
eventOutput.write(new OutboundEvent.Builder()
.id(decodedToken)
.name("responseBody")
.data(String.class, respBody.toString()).build());
关于javascript - 服务器发送的事件在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49795511/