标签:web push jsp
push-html-stream.jsp
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY BGCOLOR="blue" TEXT="white">
<%
try {
for (int i=1; i < 10; i++) {
out.print("<h1>"+i+"</h1>");
out.flush();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
out.print("<h1>"+e+"</h1>");
}
}
} catch (Exception e) {
out.print("<h1>"+e+"</h1>");
}
out.print("<h1>DONE</h1>");
%>
</BODY>
</HTML>
本文展示了一个使用JSP实现的简单流式推送示例。该示例每隔三秒向客户端发送一个数字,从1到9,之后显示完成信息。通过禁用缓存并设置正确的Content-Type,确保了数据能实时推送给浏览器。
36

被折叠的 条评论
为什么被折叠?



