jQuery in Action, 3rd edition
The moose likes Struts and the fly likes saveToken & isTokenValid don't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "saveToken & isTokenValid don Watch "saveToken & isTokenValid don New topic

saveToken & isTokenValid don't work

Abhijit Sarkar

Joined: Apr 16, 2006
Posts: 20
My application requires that soon after the user logs in, some one-time tasks are to be performed (setting his login name, role in the session) and then he's to be presented with a welcome page. Now if he refreshes the welcome page, this initial tasks are run again. I've tried my best to stop it using saveToken and associates but in vain. Please help.


<TR align="center"><TD HEIGHT="10%" CLASS="Footer" colspan="2">
<bean-el:message key="abhijit.copyright"/></TD>

TokenProcessor tokenProcessor = TokenProcessor.getInstance();
tokenProcessor.saveToken( request );
<TR> <TD WIDTH="100%" CLASS="Body">
<html-el:form action="/loginAction">


if( isTokenValid( request, true ) ) {
//one-time tasks
//redirct to error page

God knows why the if-condition is never evaluated to be true.

Thanking in anticipation
Ravi Seshu
Ranch Hand

Joined: Mar 19, 2005
Posts: 38
u can take the help of a flag variable in ur jsp page/session , chk its value then go ... ok try this.

Abhijit Sarkar

Joined: Apr 16, 2006
Posts: 20
HI Eswar,
Thanks very much but that's exactly what Struts does for me. The flag you are talking about is org.apache.struts.taglib.html.TOKEN which is set in the session and later the value sent through a request is checked against the one set in the session.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am not sure about using tokens to solve this problem...it might work. My first thought is that you should have one action that does the initial login processing. That action should have a forward that passes control onto another action (say DisplayWelcome.do) with redirect set to true. When the user refreshes the page it will just call the DisplayWelcome action.

- Brent
Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
hello Abhijit,
i faced the same problem.
You can surely solve this problem using Tokens.
The only thing required is that you should save that Token before loading that page. i mean in your code you have writtem saveToken and isTokenValid in same page. so isTokenValid always return false.saveToken must be before isTokenValid and on different page.
Tell me if this is working or not.


Yuvaraja Lskl

Joined: May 30, 2006
Posts: 1
For this problem nothing to do with the jsp u just do the following things
To avoid resubmission of form when we refresh the form, follow these two steps in your Action Class.



return mapping.findForward(target);


If ( isTokenValid(request,true)){

Your code which should not execute again, when we refresh/resubmit the form.

saivenu madhav

Joined: Nov 15, 2007
Posts: 29
If i am using the same action not DisapatchAction ..

How can i use saveToken & IsTokenVliad method()

COuld any one please given some example?

Currently i am using the following code which is not working
I agree. Here's the link: http://aspose.com/file-tools
subject: saveToken & isTokenValid don't work
It's not a secret anymore!