0

内容.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <iframe src="Response.jsp">
    </iframe>
    </body>
    </html>

响应.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%="Loading..." %>
    <%
    try{
    Thread.sleep(6000);
    }
    catch(Exception e){

    }
    %>
    <%="Loaded" %>
    </body>
    </html>

在上面的代码中,我希望像在 i 框架中一样,“Loaded”应该在“Loading”6 秒后打印,但在这里它们“Loading...”和“Loaded”在 6 秒后同时打印。我尝试使用flush()和flush Buffer()但是如果我更改了“正在加载...”,因为"<H1> Loading... </H1>"它可以正常工作。但我需要知道还有其他方法吗???谢谢。

4

1 回答 1

0

The server is sending the response as a single html page. So even though you put a sleep between the two statements both will displayed at client side at the same time. There are several approaches to do this.

Have a look at Commet

于 2013-04-17T12:42:05.607 回答