Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Refresh causing action to execute again

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
author & internet detective
Posts: 41967
911
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
Take a look at generateToken() and isTokenValid() in the Action class. They make sure that the same request can only be submitted once.
 
Author
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic