World of tricky Core Java Q and A Covering Object Oriented Analysis and Design, JVM Internals,Java Language Fundamentals,Datatypes,Keywords,Operators and Assignments,Identifies,Declarations and Modifiers, Conversion,Casting and Promotion, Flow control,Assertions, Exception Handling and Garbage Collection,Objects and Classes), Basic Packages and their classes,JDBC,JFC Swing,Java Server Pages (JSP), Servlets,EJB,JMS,JNDI etc and Open source technologies like Struts,Hibernate,Spring etc
Search This Blog
Friday, April 18, 2008
How to handle duplicate submits in Struts?
The duplicate form submission occurs-When a user clicks the Submit button more than once before the response is sent back or- When a client accesses a view by returning to a previously bookmarked page.It may result in inconsistent transactions and must be avoided.In Struts this problem can be handled by using the saveToken() and isTokenValid() methods of Action class. saveToken() method creates a token (a unique string) and saves that in the user's current session, while isTokenValid() checks if the token stored in the user's current session is the same as that was passed as the request parameter.It can be done by loading JSP through an Action and before loading the JSP call saveToken() to save the token in the user session. When the form is submitted, check the token against that in the session by calling isTokenValid
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment