【问题标题】:Display messesge wait....as background processing happening显示消息等待....作为后台处理发生
【发布时间】:2012-04-06 13:22:02
【问题描述】:

我想将消息显示为“请稍候......”,直到我的 java 代码完成一些处理。

page1.jsp - 我的表单,其中有文本框和提交按钮。 当点击提交按钮时,我正在提交表单并调用 page2.jsp

在 page2.jsp 中,我从 page1.jsp 请求参数并传递给我的 java 方法,该方法返回我的用户 ID。

userid = myclass.mymethod(); 
if(userid!=null){ 
out.println("Record is in process.Please wait"); 
} 
response.sendredirect("page3.jsp?"+userid=userId); 

在 page3.jsp 中,我正在对同时在 page2.jsp 中获得的用户 ID 进行处理。

someid =request.getparameter(userid); 
process(someid ); 

但是在所有处理完成后会显示“等待”消息。我想在获得 userId 后立即显示它。并继续对该 userId 进行后台处理。

【问题讨论】:

  • 你必须使用ajax来显示等待消息...
  • 或者,您可以使用 out.flush();但它不像拉梅什建议的那样可靠。使用 flush 方法,您必须通过在等待消息之前在页面开头添加填充文本来强制浏览器(主要是 IE)开始渲染。如果您想发布代码,请索取代码。
  • @rickz .是的,你能发布代码吗?

标签: jsp


【解决方案1】:

您可以使用 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>

【讨论】:

    【解决方案2】:

    我在 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>
    

    【讨论】:

    • 谢谢它的工作。我错过了 out.flush() 因为它没有显示混乱。
    • 嗨@rickz。处理完成后,我将显示“已完成处理”消息。但是那个时候我想在jsp中隐藏“请稍候..”消息。你能指导我如何去做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 2021-12-27
    相关资源
    最近更新 更多