-
How can I restrict the multiple data insertions
In a Struts application when click on submit it is performing some data base insertion but the end user is keep on clicking on "submit" then how can i restrict the multiple data (means same data form jsp) insertions?
Question asked by visitor pandu
-
Junior Member
Re: How can I restrict the multiple data insertions
Yoy have to write the externally as follows
int i=request.getparameter("id");
resultset rs="stmt.executequery("select id form user where id='+i+'); i
f(rs.next!=true)
{ stmt.executequery("insert into user values());
}
-
Junior Member
Re: How can I restrict the multiple data insertions
We can control this in mutiple ways.
1. Disable Submit button after first submission (but it fails when user click F5-refresh)
2. Use Struts Tokens
you need two action methods, one is for show the JSP and another is for save data
1. First you have to set the token in first action class method
saveToken(request);
return mapping.findForward(target);
2. and then validate token in save method
if (isTokenValid(request)) {
resetToken();
}
else {
mapping.findForward("errorPage");
}
... code for further processing
But it fails in click browser back button and resubmit. In those cases use redirection instead of forwarding.
you can use combination above for your problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules