JSP处理消息

And*_*oid 1 jsp servlets

probalby一个很简单的问题,但这不是我经常使用的领域......

我有html页面"start.html"有通过post请求调用serverlet的表单.这个servlet(JSP)是action.java,我有:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
    //please show a message that I am working

    // here is some code which takes some time
    response.sendRedirect(http://result.html);


}
Run Code Online (Sandbox Code Playgroud)

所以我做了一些处理,然后我显示了一个页面result.html.这一切都很好,问题是在按下start.html中的发送按钮后,我只看到系统正在处理IE中的这个小旋转轮,然后我得到了结果.大多数人可能会错过这个小指标.我想有一个中间页面或带有进度条,旋转轮甚至只有消息"请耐心等待".尽可能简单.我怎样才能做到这一点?

谢谢!

Bal*_*usC 6

只需在表单中加载一个动画gif,最初使用CSS隐藏它,然后在提交表单时使用JavaScript显示它.只要您不向HTTP响应写入任何字节,当前页面就会长时间停留在浏览器中而不会出现空白.

例如:

<form onsubmit="document.getElementById('loading').style.display='block'">
    ...

    <img id="loading" src="loading.gif" style="display: none;" />
</form>
Run Code Online (Sandbox Code Playgroud)

(你应该把它放在.js.css文件中)

你可以从Ajaxload.info获得一些不错的图像.