SSE 的使用方法可以参考:https://blog.csdn.net/xiewz1112/article/details/80591898
EventSource 对象的 API 文档地址:https://developer.mozilla.org/en-US/docs/Web/API/EventSource
SSE 的使用示例(主要代码来自《Java EE 开发的颠覆者 Spring Boot 实战》一书的 4.5.3 部分)
1. 页面sse.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SSE Demo</title>
</head>
<body>
<div id="msgFromPush"></div>
<script type="text/javascript" src="<%=request.getContextPath()%>/assets/js/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
if (window.EventSource) {
console.log("该浏览器支持SSE");
var source = new EventSource("ssePush");
var s = "";
source.addEventListener("open", function(e) {
console.log("连接打开");
}, false);