File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes please observe this snippet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "please observe this snippet" Watch "please observe this snippet" New topic

please observe this snippet

A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114

please ignore servlet and bean codes used in this question i s ,this will disply one form and if i submit it will go for validation first then go to servlet which then store in i entered the 10 sql prompt it shows 10 rows created.

now my problem started ,if i came to form agin and press the F5 key(refresh) button then go to sql prompt and if we see the no of records created is 11 records.why it is happening like this .how to restrict the control doesn't goto database.

plese give me the kind reply earliest.


Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
Too much code.
Irrelevant code in any case.

When you "refresh" a page, you send to the browser the exactly the same request you sent it last time.
If it is a "save" request, then it runs the save code again.

One common approach to prevent this is that after a "save" request, you redirect to a "display" page. Then if the user refreshes that page, they only refresh the "display" request, not the save request.
It makes it a bit harder for them to screw things up with reloading pages anyway.

An article on the subject:
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi all,
briefly my question is-My form data is submitting to database through controller.
if i press keyboard f5 button again the same data is submitting to the database.

for to solve that i used

cache-control,pragma headers used in jsp.but now also same form data is submitted to database.

i want to restrict that duplicate submittion.

how it is?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Stefan answered your question in his 3rd paragraph.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: please observe this snippet
jQuery in Action, 3rd edition