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!
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
posted
0
no you can't. The forward acts as a return statement so you can't follow it with code.
42
James Lye
Greenhorn
Joined: Nov 12, 2004
Posts: 6
posted
0
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
Joined: Oct 12, 2000
Posts: 5093
posted
0
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
Joined: Nov 12, 2004
Posts: 6
posted
0
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.
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.
You can also use Javascript to disable the submit button so the user can only click it once.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi