This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, Within a jsp page, I have this <form> that allows a customer to add a product to my db. After submitting the form (action="samepage.jsp"), the product is added to the db. The problem: When I right-click>Refresh (on IE), the same product ('i.e same name') is added to the db (the form is cleared). Whats going on here, and how do I prevent this from happening without disabling Refresh? I have these header directives.
1) When your form is generated, create a unique token value -- usually using the system clock time. 2) Place this value in your form as a hidden form element. 3) Also place the value into the session. 4) When the form is submitted, compare the two values. If they match, remove the session token and proceed. If they don't match, or the session token is missing, you know that the form is being "resubmitted" and you can deal with the situation as appropriate to your application.
You should have Primary key in your db either product name or product id. Put constraints on it so that it won't allow duplicate raw. Alternatively, before inserting product into db, check first wheter product with same name already exist, if yes do not insert and return to client with valid error description.
If you want to become a rich, do not work for others but make others to work for you.