How to handle Idempotency issue...with doPost()... ?

How to handle idempotency issue of methods like doPost ... in servlets.. ?
[81 byte] By [Shebua] at [2007-11-27 9:41:51]
# 1
Can you please elaborate the "issue" a bit more? Do you want to prohibit idempotency in POST? Why?
BalusCa at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi...

thanks for reply whatsoever... I try explain my side with this example...

Suppose I use doPost() in my form... and on click of submit button the form does some updates/transaction in the database server. Now if I again click the submit button, because for somke reasons I didn't get confirmation page... , the update / transaction will be commited again.

Am I right ... ?

Now my query is how do I escape from this disastrous happening... ?

I hope I am able to explain my side more clear... hope you will now understand what I am saying and what I want help on ?

Shebua at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Do a redirect after processing the post.
BalusCa at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
didn't get you.. can u explain a bit ?
Shebua at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

PseudocodedoPost(request, response) {

// Do your thing to process the request.

// When the processing is finished, then do

response.sendRedirect("confirmationpage.jsp");

}

BalusCa at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
> How to handle idempotency issue of methods like> doPost ... in servlets.. ?Do you mean to say how to avoid click of Submit button twice?
krajnisha at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
It's indeed an odd question, because per definition the POST is never idempotent. That's why I asked him to elaborate the "issue".
BalusCa at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

I use two approaches:

1. transaction id, when I display page I put unique transaction id on it in a hidden field. For every submit I check if there was transaction with such id finished or in progress and discard.

2. disable submit button in JS and then process submit (this method less robust but easy to develop).

Wow I almost 10 years with this forum.

dmitryra at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

hi..

thanks for reply... I liked your solution...

But if you don't mind, since I am very new to programming & Java, can you elaborate the solutions you provided... I mean in terms of some codes...? Like when to define/ allocate transaction id, how and where to define it .... when and where to check and what to do if it already exists... ?

Second disabeling submit button how .. when... till when .. and when to enable it again ?

Waiting for reply asap.

Shebua at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
yes
Shebua at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

Form transactional submission is a standard feture of servlet framework we use. So generally extraction of code snippet can be difficult for me. I'd recommend to try Javaranch forum. Those guys may have some code solutions ready for sharing.

For JS it may look like:

document.myform.onsubmit=function() {

myform.submitbutton.enabled=false;

return true;

}

You may consult with JS developer though, because I do not do actual development.

dmitryra at 2007-7-12 23:21:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...