加载servlet时显示内容 [英] Display something while servlet loads

查看:81
本文介绍了加载servlet时显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Web应用程序,其中运行一个servlet会花费一些时间,一旦完成servlet,将显示一个jsp页面,其中包含来自较早运行的servlet的数据.

I have a java web application wherein a servlet runs that takes time to load, and once the servlet is done a jsp page will be displayed with the data from the servlet that ran earlier.

在加载servlet时是否有显示消息或gif的方法?

Is there a way to display a message or a gif while the servlet is loading?

推荐答案

JavaScript是必经之路,Servlet是服务器端.

JavaScript is the way to go, Servlet is server-side you know.

据我所知,一旦浏览器提交请求,我们就无法控制将要加载的页面.

As long as I know, once browser submits a request we can't control what happens until next page is loaded.

因此,您可以在加载新页面之前处理延迟,或者在页面加载之后处理延迟.当然,在完成身份验证之前,很难加载需要身份验证的页面,因此最好保持登录页面直到发生.

So, either you handle lag before loading the new page, or you handle lag after page is loaded. Of course, it's hard to load a page that requires authentication, before authentication is done, so better keep on login page until it happens.

我的建议是您使用AJAX处理登录,始终注意安全性.您的JS不会让浏览器提交表单,而是会收集登录信息并使用AJAX异步发送到Servlet.我不知道该怎么做,但是可以做到的.

My suggestion is that you handle login with AJAX, always being careful with security. Instead of letting browser submit the form, your JS gathers login information and asynchronously sends to Servlet using AJAX. I don't know how to do it but it can be done.

当JS等待响应时,您会创建一些动画来分散用户的注意力.响应到来后,如果登录成功,您的JS将加载新页面.

While your JS wait for response, you create some animation to distract user. Once response comes, if it login succeeds, your JS loads the new page.

这篇关于加载servlet时显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆