• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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."
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 4803
    7
    Mac OS X VI Editor Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic