我想将消息显示为"请稍候......."Tilll 我的 Java 代码完成了一些处理。
page1.jsp - 我的表单,其中有文本框和提交按钮。当单击提交按钮时,我正在执行表单提交并调用页面2.jsp
在第 2 页中.jsp我从第 1 页请求参数.jsp并传递给我的 java 方法,该方法返回我的 userid。
userid = myclass.mymethod();
if(userid!=null){
out.println("Record is in process.Please wait");
}
response.sendredirect("page3.jsp?"+userid=userId);
在第 3 页中.jsp我正在同时处理我在第 2 页中获得的用户 ID.jsp。
someid =request.getparameter(userid);
process(someid );
但是在所有处理完成后会显示"等待"消息。我想在获得用户 ID 后立即显示它。并继续对该用户 ID 进行后台处理。
你可以使用javascript来做很多事情。这里有一个想法。
<html>
<body>
<div id="wait">
Some text here is necessary here for the IE browser to start displaying.
Otherwise it will wait until it receives enough of a response to begin displaying anything.
I am not sure how much padding is necessary. This works in IE 8.
<%
out.print("<little.gif' />");
out.flush();
for(int x = 0; x < 3; x++){
out.print("<br/>Processing!");
out.flush();
Thread.sleep(3000); //mock processing
}
%>
<br/></div>
<script>
alert("Finished processing.");
document.getElementById("wait").innerHTML = "Here are the results...";
</script>
</body>
</html>
我在IE8和Chrome 18中进行了测试。如果您的服务器有限制,则可能会遇到问题。例如,它不适用于Google App Engine。
<html>
<body>
Some text here is necessary here for the IE browser to start displaying.
Otherwise it will wait until it receives enough of a response to begin displaying anything.
I am not sure how much padding is necessary. This works in IE 8.
<%
out.print("<loading.gif' />");
out.flush();
//mock processing
for(int x = 0; x < 3; x++){
out.print("<br/>Processing!");
out.flush();
Thread.sleep(3000);
}
%>
<br/>Finished processing. Here are the results...
</body>
</html>