我创建了一个JSP,它将创建潜在的无限量的输出。
当我告诉浏览器停止时,浏览器停止了,但控制台告诉我JSP的servlet一直在运行。
我想知道是否以及如何修改此代码,以便在浏览器停止接收数据时停止:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" errorPage="ExcessOutputErrorPage.jsp" %>
<%@ page import="de.svenjacobs.loremipsum.LoremIpsum" %>
<%@ page buffer="8kb" autoFlush="true" %>
<%!
private int dumpCount = 0;
private String nextDump()
{
dumpCount++;
String dumpHeader = "Dumping " + dumpCount + " paragraphs";
String dump = "<h2>" + dumpHeader + "</h2>";
LoremIpsum loremIpsum = new LoremIpsum();
System.out.println(dumpHeader);
for (int i=0; i<dumpCount; i++)
{
dump += "<p>" + loremIpsum.getParagraphs(1) + "</p>";
}
return dump;
}
%>
<!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=ISO-8859-1">
<title>Large Amount of Text</title>
</head>
<body>
<h1>Large Amount of Text</h1>
<%
boolean doDump = true;
while (doDump)
{
out.println(nextDump());
out.flush();
}
%>
</body>
</html>