I created a JSP which will create a potentially infinite amount of output.
When I told the browser to stop, the browser stopped, but my console told me that the JSP's servlet kept going and going and going.
I'm wondering whether and how I could modify this code so that it will stop if the browser stops receiving data:
<%@ 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>