• Post Reply Bookmark Topic Watch Topic
  • New Topic

How does post() method serve the purpose of non-idempotence?

 
Loganathan Karunakaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a doubt regarding idempotence. I read in head-first servlets and jsp that post() methods are non-idempotent as per specification.
Say, I have a link which calls a post() method that updates some thing in database. Does it mean that if I click twice or thrice, it will invoke only once.

How post() methods server the purpose of non-idempotence.

Thanks in Advance.
Loganathan. K
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loganathan Karunakaran wrote:
Say, I have a link which calls a post() method that updates some thing in database. Does it mean that if I click twice or thrice, it will invoke only once.


Idempotence means that the resulting action IS the same no matter how many times it is triggered.

Using the example of INSERT a record to database, when POST is triggered twice, 2 records will be inserted to database. Therefore, POST is considered non-idempotent.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loganathan, you have it backwards: the servlet engine doesn't enforce anything, it merely assumes that a GET will be idempotent, and a POST won't. It is the developer's responsibility to ensure that what the doGet method does is, in fact, idempotent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!