File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Refresh causing action to execute again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Refresh causing action to execute again" Watch "Refresh causing action to execute again" New topic
Author

Refresh causing action to execute again

Jolly Khanna
Greenhorn

Joined: Sep 24, 2001
Posts: 12
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Take a look at generateToken() and isTokenValid() in the Action class. They make sure that the same request can only be submitted once.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sue Spielman
Author
Ranch Hand

Joined: Apr 21, 2003
Posts: 56
Jolly:
A sample of how to handle and use tokens is provided in chapter 4 'Creating and Building Actions' in my book.
Sue


President/Consulting Engineer<br />Switchback Software LLC<br /><a href="http://www.switchbacksoftware.com" target="_blank" rel="nofollow">www.switchbacksoftware.com</a>
Jolly Khanna
Greenhorn

Joined: Sep 24, 2001
Posts: 12
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
 
subject: Refresh causing action to execute again