• 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

Can a servlet forward 2 web pages?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In order to prevent double submission on a form, I intend to display a temporary web page after the first submit, informing the surfer to wait while his transaction is in progress. The program will continue to process the transaction and display a 2nd web page when the transaction is successful. Does anyone knows how this can be done using servlets? I tried the following in doPost:

RequestDespatcher.include(req, res) //use include to display the temp page
//process the trxn
RequestDespatcher.forward(req, res) //display the successful trxn web page
but encountered "Cannot forward a response that is already committed"

I'm new to Java so I would really appreciate if someone could help me out.
Thanks!
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no you can't.
The forward acts as a return statement so you can't follow it with code.
 
James Lye
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. In that case how can I implement the following using servlets?
1. Surfer submits form.
2. Server displays a temp web page.
3. Server processes transaction.
4. Server returns a transaction successful web page.

Thanks for your help.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not readily.
You start the transaction in a separate thread and forward to the "please wait" page. This page every few seconds does a request to the server through Javascript. If the transaction isn't yet complete the servlet it polls sends back no data and the page remains. If it does send back data that will be the URL of the next page to go to (probably a page telling what was the result) and you can through Javascript go there.
 
James Lye
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right. I'll try that out.
Thanks for your help.

Actually I'm looking for ways to handle double submissions on the server side. Anyone else with other ideas. Do let me know.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To prevent double transmissions, you can use the "token" concept. On the first request, you put something in the session. If it is there on the second request, you don't start processing again.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also use Javascript to disable the submit button so the user can only click it once.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic