servlet实现的WEB PUSH(SEVER PUSH)

4 views
Skip to first unread message

youn...@gmail.com

unread,
Nov 3, 2008, 10:04:37 PM11/3/08
to 工作记录
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>


-

文章出处:http://www.diybl.com/course/4_webprogram/jsp/jsp_js/
2008515/116199.html

youn...@gmail.com

unread,
Nov 3, 2008, 10:04:57 PM11/3/08
to 工作记录
From www.servlets.com,
Book: Java Servlet Programming 2nd Edition, Oreilly


public void doGet(HttpServletRequest req,
HttpServletResponse res)

throws ServletException, IOException {
ServletOutputStream out =
res.getOutputStream(); // some binary output

// Prepare a multipart response
MultipartResponse multi = new
MultipartResponse(res);

// First send a countdown
for (int i = 10; i > 0; i--) {
multi.startResponse("text/plain");
out.println(i + "...");
multi.endResponse();
try { Thread.sleep(1000); } catch
(InterruptedException e) { }
}

// Then send the launch image
multi.startResponse("image/gif");
try {
ServletUtils.returnFile(req.getRealPath(LAUNCH),
out);
}
catch (FileNotFoundException e) {
throw new ServletException("Could not find
file: " + e.getMessage());
}

// Don't forget to end the multipart
response
multi.finish();
}

youn...@gmail.com

unread,
Nov 4, 2008, 1:40:29 AM11/4/08
to 工作记录

youn...@gmail.com

unread,
Nov 4, 2008, 1:49:53 AM11/4/08
to 工作记录
Reply all
Reply to author
Forward
0 new messages