File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Refresh causing action to execute again

Jolly Khanna

Joined: Sep 24, 2001
Posts: 12
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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Sue Spielman
Ranch Hand

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

President/Consulting Engineer<br />Switchback Software LLC<br /><a href="" target="_blank" rel="nofollow"></a>
Jolly Khanna

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:
...(update the datebase)
The problem is isTokenValid ALWAYS returns false. It doesn't matter where I put saveToke(). Does any one have any ideas?
I agree. Here's the link:
subject: Refresh causing action to execute again
It's not a secret anymore!