Problem with Request object

In my JSP page, I have a text box and button. When enter product name and click button, the request goes to servlet, product is created in the database, page redirected to JSP with RequestDispatcher. The problem is after creating the product, if I press F5 again, the servlet is called and tries to create the product again, which is just before created. i.e. I type "MPX101" and click button, I get alert message "MPX101 is created" and textbox is empty (obviously). I press F5 and I get an alert message "MPX101 already exists".

The same thing happens with another page for delete. If I press F5 immediately after deletion of an item, again same item is being tried to delete.

When I traced request object, still it contains product name, which I created already. Can we clear contents of request (after creating of product and JSP is loaded, in my case) ? Any sort of help is greatly appreciated. Thanks in advance.

I posted same thread at

http://forum.java.sun.com/thread.jspa?threadID=5170963&tstart=0

So that people from JSP forum also can view this...

[1100 byte] By [baskarka] at [2007-11-27 3:56:05]
# 1

You can't "clear the request object", because it's set up to represent the request coming from the browser. If you press F5 it's expected behaviour for the browser to try the same request again.

After the insert or delete, your app needs to redirect to another page, perhaps confirming the item has been inserted or deleted. Or, after the insert, you could redirect to a page that shows details of the new item; after delete you could redirect to a list of the items still in the database.

Alternatively, use a POST request for actually requesting the insert/delete; then if the user presses F5 they'll get a warning.

Have a look at this:

http://en.wikipedia.org/wiki/Post/Redirect/Get

RichFearna at 2007-7-12 9:00:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...