This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a Servlet which performs a login task, but it takes some time to load because it uses a webservice that it is not very fast.
So, I'd like to display to the user a message saying "Please wait a little bit". How could I do that?
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.
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.
While your JS wait for response, you create some animation to distract user. Once responce comes, if it login succeeds, your JS loads the new page.