File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Using Struts tokens to do this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using Struts tokens to do this?" Watch "Using Struts tokens to do this?" New topic

Using Struts tokens to do this?

A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
I have a very simple web app - a page to allow users to select various report selection criteria, the other displays the criteria results with a button which puts them back to the search criteria page i.e calls the app startup action!
2 problems -
1. To prevent users bookmarking the report page.
2. To allow users to use the "back" button from the report results page, make ADDITIONAl changes & redisplay the results.
For the the bookmarking problem I have this code forcing them back to the start of the application which works fine -
return (mapping.findForward("invalidAccess"));
But I'm stuck on the "back" button one, if I make selections, display the report, click "back", make a change & try to show reports page I get redirected back to start of app as the isTokenValid() fails
Can I get around this? - it's annoying to the users to have to redo all the selections each time!
thanks - hopefully not to badly explained?
This works well! - but
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
The Struts token mechanism is designed to prevent people from double submitting by submitting, clicking back, then submitting again.
You want to use it to do the opposite of what it was intended for, no wonder you're having trouble
A simple solution for this might be to include on the selection form a hidden field like <input type='hidden' name='valid' value='true'> then check for it in your report action. Instead of isTokenValid(), use something like if( request.getParameter("valid") != null ). Unless the request is coming from your selection page, the 'valid' param won't be there.
[ January 08, 2004: Message edited by: Ray Stojonic ]
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
Cheers for that Ray, works brilliantly, got a bit confused with the token stuff but as normal resolutions are often very simple!
I agree. Here's the link:
subject: Using Struts tokens to do this?
It's not a secret anymore!