I have a comments page. This page must display the list of comments stored in the database. This page contains two buttons. Add comment and Cancel. The Add Comment button takes us to the screen where you can type in a comment and save it.
Issue: When I add a new comment and return back to the comments page, it shows the newly added comment, which is right. When I hit the refresh button on the browser, the newly added comment is added once more. Everytime I click on the refresh buton, the comment keeps adding to the list.
So, After adding the comment and returning to this action class, the refresh button is calling this action in which the request parameter is still set to "addComment" and thats why a new comment is added everytime.
After your servlet has added the comment to the DB, redirect rather than forward. The refresh is resending the add request every time it is clicked. By preforming a redirect, the most recent action is not the add operation.
What does this have to do with request.getParameter()?
Arg, I posted a reply as it was being moved and lost it when the post was move... lets see where I was...
Off hand I'd say its because you keep submitting the same data over and over again. Have you tried, after submitting, to refresh the page not by using the refresh button but by using a bookmark or typing the URL in directly? If it still happens, then I would say you have a left over variable some where.
For Comments pages of websites I like to store the user's IP address and not allow more than one submission per IP address. This is an easy solution that also eliminates spamming from a particular user. If you are using a database to store your comments its even easier since you can just set a primary key or unique-ness constraint on the ip address.