This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refresh causing action to execute again

 
Jolly Khanna
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is the best approach or solution for the following problem:
I have a jsp page that calls an action class which, in turn, deducts a value from the database. Upon completion of this deduciton, the page gets sent to "success.jsp", but when I right-click the jsp page and click on "refresh" the action gets called again and another deduction takes place. For example, I have a DB column called "Amount" and the initial value is 10. When the user logs in I want to deduct 1 from amount. "success.jsp" show the amount with the value of "9". When I click on refresh, it says "8", then "7", "6", etc. Is there a way to prevent the action from executing and, subsequently, updating the database everytime a user tries to refresh?
Any help would be greatly appreciated.
Thanks!!!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at generateToken() and isTokenValid() in the Action class. They make sure that the same request can only be submitted once.
 
Sue Spielman
Author
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jolly:
A sample of how to handle and use tokens is provided in chapter 4 'Creating and Building Actions' in my book.
Sue
 
Jolly Khanna
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for informing me about Stuts token's. I tried to use them but it's a little confusing. I've tried it many different ways but none seem to work. Below is the code snippet that is causing me problems:
if(isTokenValid(request))
{
resetToken(request)
try
{
...(update the datebase)
saveToken(request)
}
}
The problem is isTokenValid ALWAYS returns false. It doesn't matter where I put saveToke(). Does any one have any ideas?
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic