Explain about token feature in Struts

Showing Answers 1 - 9 of 9 Answers

abhishek roy

  • Jun 11th, 2005
 

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())

Manoj

  • Jul 7th, 2005
 

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.

  Was this answer useful?  Yes

Amzad Basha

  • May 20th, 2006
 

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.

KIRAN

  • Aug 9th, 2006
 

hi abhi

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

Plz send to me the  reply

  Was this answer useful?  Yes

krish

  • Oct 26th, 2006
 

In classes we will write the Tocken code

  Was this answer useful?  Yes

VK

  • Jun 15th, 2007
 

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.




Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions