aspose file tools*
The moose likes Struts and the fly likes struts tokens not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts tokens not working" Watch "struts tokens not working" New topic
Author

struts tokens not working

K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
I'm trying to prevent multiple submits of a page from hitting the "refresh" browser button.
I have tried putting in the code to use tokens, but it does not work.
In action class 1, I have put "saveToken(request)" when loading the jsp's data.
When the user hits the continue button, it goes back to action class 1 and redirects to action class 2, where it processes data and displays the results in jsp 2. I am checking isTokenValid(request) in action class 2 (as that is the one that will be accessed when the user hits the refresh button) but it is always false, so nothing is ever processed.
Does the struts token thing not work when linking action classes?
Just to check, I put an isTokenValid(request) line in the code where I'm checking if the continue button was pushed, and that is working fine....so it will work if the user hits the "back" button, but what can I do about hitting the "refresh" button on the results page?

Here is a quick little psuedo-code of what I'm doing:

action class 1:

if (continueButton != null)
{
setContinueButton(null);
if (isTokenValid(request))
{
//do some stuff
//forward to action class 2
resetToken(request);
}
else
{
//forward to jsp2 without doing anything
}
}
else
{
loadPage();
saveToken(request);
forward = mapping.findForward("jsp1");
}


action class 2:
if (isTokenValid(request))
{
//process data
//display results
resetToken(request);
}
//forward to jsp2
[ May 10, 2006: Message edited by: K Dombroski ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I would think you would not want to call resetToken from Action1 in the code that will forward on to Action2. The call to resetToken clears the token value from the session so that all future calls to isTokenValid will return false until another token is created by calling saveToken. BTW, are you redirecting to Action2? If so that would clear the token value from the request.

- Brent
K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
it didn't work even without resetting the token beofre going to action2. but yes, i am redirecting to action2. i discovered that if i didn't, it woulnd't pick up anything that i had done in the action class before redirecting and would instead take the original request from the jsp submission and send THAT to the 2nd action class, which i didn't want it to do. is there a way to link the action classes without losing the request AND without losing changes made to it in the first action class? or am i just going to have to figure out another way to handle the dual submission without using tokens?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts tokens not working