• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts tokens not working

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic