I Assume you have an Action (preferred approach) or otherwise code in JSP to insert the data into the Db (bad design). Either ways from where the request is being serviced if you check if the values are already in the database you can find out if the particular request is from a page refresh.
use a counter with session. send the counter as query string or hidden form field on every response page. now whenever you receive a request check the value of the counter. if the value received from the request is less then the counter value in the session, then it is a request from a refresh. if the counter from the request is equal to the session counter then the request is through some action. then do the action, add one to the counter in the session and send the new counter to the user.
I think this will solve your problem.... [ August 22, 2008: Message edited by: Ankit Garg ]
Originally posted by Mayur Somani: @RajKamal Yes I know that it is bad design but I was not developing an enterprise app. It was just a little experiment.
And the bad design is now limiting your functionality. Time to fix it.
1) Your form posts to a Servlet (and has all the no-cache headers set). 2) The Servlet processes the form by putting data into the database 3) The Servlet uses response.sendRedirect(...) to a display page 4) The display page shows the data and when you refresh does not re-post. Pressing the back button won't repost either.
This will work.
Originally posted by Mayur Somani: response.sendRedirect approach leads to performance problems. Any other ideas?
And you tried it and measured it? What kind of performance problems?
The so-called "Post-Redirect-Get pattern" that Steve describes is discussed as part of this article, and is the best and proven solution to avoid the described problem, mythical performance "problems" or not. [ August 22, 2008: Message edited by: Bear Bibeault ]
"yesganesh", you have previously been warned regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.
Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Be aware that accounts with invalid display names are disabled.
Try what Ankit Garg has said...a really easy thing to do is just put a hidden field containing the timestamp onto the form you are submitting and on the action (servlet) check for it on the session. If it exists and is not the same OR is not on the session do your stuff and save it onto the session so if you resubmit with refresh the equals will evaluate to true and will skip the action. It is called the Synchronizer Token Pattern. Just google for it and choose an article to get some in-depth knowledge about it.