GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Struts
Go To First  |  Previous Question  |  Next Question 
 Struts  |  Question 14 of 103    Print  
Explain about token feature in Struts

  
Total Answers and Comments: 7 Last Update: June 15, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Amzad Basha
 
Struts has a token feature that puts a single-use token on a form to prevent duplicate submits. Redirecting after post prevents duplicate submissions using the "back" button but will not prevent a duplicate post if a user submits more than once in rapid succession.

Typically when a Struts action is going to forward to a page that will post information the action will call Action.saveToken(HttpServletRequest). Struts will then automatically add the token to the form when the <html:form> tag is rendered.

When the post occurs the action should perform an Action.isValidToken(HttpServletRequest, true) to verify and invalidate the token. Any succeeding posts with the token will be cause isValidToken() to return false.

Above answer was rated as good by the following members:
pradeepkmr18, batswon
June 11, 2005 14:15:44   #1  
abhishek roy        

RE: Explain about token feature in Struts
Tokens are used to check for invalid path for by the uer:
1) if the user presses back button and submits the same page
2)or if the user refreshes the page which will result to the resubmit of the previous action and might lead to unstabality..

to solve the abv probs we use tokens
1) in previous action type saveTokens(HttpServletreuest)
2) in current action check for duplication bu
if(!isValidToken())

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 07, 2005 22:13:45   #2  
Manoj        

RE: Explain about token feature in Struts
Another important usage of tokens is to trap an event when the user hits the Submit button twice. Tokens allows to prevent duplicate processing for such a request.
 
Is this answer useful? Yes | No
April 27, 2006 10:13:08   #3  
ansh_ranjan Member Since: April 2006   Contribution: 7    

RE: Explain about token feature in Struts

Please say what is token instruts.

Thanks in advance

Devesh

ranajnsdevesh@yahoo.co.in


 
Is this answer useful? Yes | No
May 20, 2006 07:26:53   #4  
Amzad Basha        

RE: Explain about token feature in Struts
Struts has a token feature that puts a single-use token on a form to prevent duplicate submits. Redirecting after post prevents duplicate submissions using the back button but will not prevent a duplicate post if a user submits more than once in rapid succession.

Typically when a Struts action is going to forward to a page that will post information the action will call Action.saveToken(HttpServletRequest). Struts will then automatically add the token to the form when the <html:form> tag is rendered.

When the post occurs the action should perform an Action.isValidToken(HttpServletRequest true) to verify and invalidate the token. Any succeeding posts with the token will be cause isValidToken() to return false.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 09, 2006 13:30:06   #5  
KIRAN        

RE: Explain about token feature in Struts

hi abhi

in which file we have to write tokens ? in classes ? / html ?

Plz send to me the reply


 
Is this answer useful? Yes | No
October 26, 2006 02:38:52   #6  
krish        

RE: Explain about token feature in Struts
In classes we will write the Tocken code
 
Is this answer useful? Yes | No
June 15, 2007 01:36:01   #7  
VK        

RE: Explain about token feature in Struts
Tokens are used to prevent multi click problem in struts.

In Action class method at the begining of the code need to call the saveToken() that generates an unique identifier for the "request url" and stotes it in the session and also in the jsp as hidden param to which the request forwarded to. The hidden param in jsp is automatically created by struts if we use <html:form> tag

isTokenValid() compares the users session token with the token given as a request parameter (either through hidden form field (form tag) or through additional parameter on a url (link tag)).

resetToken() removes the token from the session.





 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape