wood burning stoves 2.0*
The moose likes Servlets and the fly likes Send a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Send a "Please Wait" Page, then send a "Transaction Completed" Page" Watch "Send a "Please Wait" Page, then send a "Transaction Completed" Page" New topic
Author

Send a "Please Wait" Page, then send a "Transaction Completed" Page

Josef Stern
Greenhorn

Joined: Mar 26, 2011
Posts: 9
I am writing a servlet to perform a financial transaction. I can re-write it as several related servlets if necessary. Rather than bog down on details, I will explain what I want to accomplish, and the experienced among you will be able to advise me on how to approach this.

A doPost calls my servlet, sending it about 20 parameters. The servlet checks to make certain that the parameters are valid. If they are not, it sends a response, advising the user what is wrong, and allows for a back page to fix the errant items. All this works. My problem arise once the servlet is satisfied with the parameters, and gets down to executing the business logic.

What I want to do is display a "Please wait, we are processing your request" web page while my servlet is chugging away. After the servlet has finished, I want to display a page "Transaction is completed, print this for your records". I want the Transaction Completed page to replace the Please Wait page, but I could live with Transaction Completed appearing in a separate tab or window.

I have experimented with various forms of flush, response.setHeader(Refresh), RequestDispatcher, and redirect, but nothing quite works the way that I want it. I would prefer to avoid Javascript, but I would do it if I must.

I don't think that I need detailed code at this point. I think that I need general guidance. This is a common web transaction. I must be missing something in the bigger picture.

Thanks to all who respond,
Josef
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

Using Ajax is the best way to be able to do things exactly the way that you want (whatever that is, you don;t really say). Trying to control the flush and other stuff like that is doomed to failure and a flat spot on the side of your head.

If you aim to avoid JavaScript ( ) then a meta refresh is your best bet, but that's clunky and doesn't give you a lot of control.

What's your beef with Ajax and JavaScript? Unless you are in an environment that must support browsers with JavaScript turned off (rare these days -- it makes 99% of the useful web unusable), it's like saying "I want to bang in a nail, but I'd like to avoid using a hammer."


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

With pure HTML, what you want is two transactions, not one. The HTML specs only allow one response for each request, not two. Do it like this:
  • browser does POST/GET to kick off transaction
  • server responds with HTML page saying "please wait" that also automatically does another GET/POST for the "completion page"
  • Servlet finishes transaction and responds with normal answer


  • It can look like one POST to the user, but its really two.

    Or you can use AJAX

    Josef Stern
    Greenhorn

    Joined: Mar 26, 2011
    Posts: 9
    Bear & Pat,

    Thank you for your responses.

    Bear – I hold no grudge against AJAX or Javascript. Regarding AJAX, I am strategically lazy. I would prefer not to learn yet another language, script, code if I could avoid it. But if I must learn it, I will. Regarding Javascript, I have built my web site without it so far, and would prefer not to rely on it. It’s true that the vast majority of browsers & users have it enabled. I just want my site to be accessible to that extra 1%. But if I must use it, I will. Your suggestions give me some perspective in this matter.

    Pat – Your suggestion is the out-of-the-box insight that I sought. The first wave of HTML issues a POST for the second wave of HTML. The browser makes one POST, the servlet one response, yet two pages are displayed. If I understand this correctly, and I were crazy enough, I could set up a daisy chain of pages, each one calling the next.

    But can the first wave of HTML issue another POST without user intervention? Doesn’t the user need to press a button to initiate another POST?

    Thanks again,
    Josef

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60764
        
      65

    No disrespect meant, but that's hardly an "out of the box" insight (which I'm sure Pat will agree with) -- it's a fairly standard way of doing things prior to the advent of Ajax. And as I said, it doesn't give you a whole lot of control, which your original post seemed to indicate that you want. But if that's good enough for your purposes it is a whole lot simpler than the Ajax approach.
    Pat Farrell
    Rancher

    Joined: Aug 11, 2007
    Posts: 4646
        
        5

    Agree, is just how we did it in the olden days.
    HTTP is very simple, and has one hard and fast rule: one request gets one result. Period.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Send a "Please Wait" Page, then send a "Transaction Completed" Page
     
    Similar Threads
    How two different web application communicate with each other
    How to handle an asynchronized scenario?
    Communicate between JSP and Servlet
    forwarding request to some other server
    sending html to the browser whilst an intensive operation proceeds