aspose file tools*
The moose likes Servlets and the fly likes How to stop user entering a record twice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to stop user entering a record twice?" Watch "How to stop user entering a record twice?" New topic
Author

How to stop user entering a record twice?

R Chirag
Greenhorn

Joined: Aug 17, 2005
Posts: 2
Hi all,

I don't know whether this topic is related to servlet or jdbc. But I'm posting it here.
I'm developing an application and I want to stop user entering a record twice by pressing "Refresh" and "Back" button. Is there any Listner and/or Event to refrain user entering a record twice? [I found "Synchronizer Token pattern" but I know very little about design patterns.]

Hoping 4 ur benign reply,
Thanks in advance
Chirag.

[ August 17, 2005: Message edited by: Chirag ]
[ August 17, 2005: Message edited by: Chirag ]

SCJP [CX 310 - 035]<br />SCBCD [CX 310 - 090]
Ritesh Agrawal
Ranch Hand

Joined: Jan 08, 2004
Posts: 74
Hi Chirag,

Could you be please more specific on your requirement. I believe you have something like this.

--A Web Page containing user input form.
--On submit the form transfers the input data to server and displays a new page.
--User clicks Back or refresh and gets the input form again.
Now it seems you don't want the third step to happen. If I understand it correctly then, I can suggest two things that you need to do:

1st: It appears that your form is being displayed by a servlet and after form submission, the same servlet uses RequestDispatcher to display the confirmation or another page. So you can make the first page to be displayed by the servlet to be something else, which contains a link to the Form page. The user when clicks this link, use RequestDispatcher to open the Form page. Thus, when user clicks Refresh, always the first page will be displayed and not the Form Page. From the first page the user can go to Form Page which I think should be OK.

2nd: Back button functionality can be prevented by doing a work around. You may not allow two successful submit from the same session programatically.

If some one else can provide better or different solution I would be happy to know about that.


Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
Baiju Varugese
Ranch Hand

Joined: Dec 16, 2003
Posts: 74
Synchronized tocken is
while redirecting/loading the user form generate a token/random number and store it in the user session and also in a hidden field in the form. on submit of the form check the session token with the hidden field value if it matches do you operation else forward it to some other page, after validate the token update the session token with the new value, this will prevent the user to submit the form twise


Measure twice cut once carpenter theory <br /> <br />Baiju <br />SCJCP, SCBCD, IBM-486, IBM-484, SCEA Part I
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi Chirag,

Welcome to the ranch. Baiju Varugese was right on with the synchronized token. Also, you will need to change your name to match the
JavaRanch Naming Policy before yuou attract the attention of a bartender.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

"Chirag",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to stop user entering a record twice?