• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saveToken & isTokenValid don't work

 
Abhijit Sarkar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

Login.jsp



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

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


LoginAction.java



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


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

Thanking in anticipation
 
Ravi Seshu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
u can take the help of a flag variable in ur jsp page/session , chk its value then go ... ok try this.

-eswar
 
Abhijit Sarkar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Nishita
 
Yuvaraja Lskl
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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.



1.

saveToken(request);

return mapping.findForward(target);





2.

If ( isTokenValid(request,true)){

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

}
 
saivenu madhav
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic