防止页面刷新重复提交的方法

[ 2006-05-22 21:34:11 | Author: zhenhua ]
Font Size: Large | Medium | Small
不用考虑复杂的实现方法和思想,其实验证码就是一个最好的方法,每次提交时会随机产生一个验证码,保存时会匹配这个随机产生的一串数字,由于每次的验证码都不相同,所以只能保存一次,这样就可以防止提交后原地刷新页面重复提交。
至于随机验证码的保存和匹配方法,大都用Session,正在研究更高效的算法。

最简单的方法,随机产生四个数字:
Quote
public String getNumber() {
int i1 = (int) (java.lang.Math.random() * 10);
int i2 = (int) (java.lang.Math.random() * 10);
int i3 = (int) (java.lang.Math.random() * 10);
int i4 = (int) (java.lang.Math.random() * 10);

return String.valueOf(i1) + String.valueOf(i2) + String.valueOf(i3) + String.valueOf(i4);
}

Comments Feed Comments Feed: http://www.zhenhua.org/feed.asp?q=comment&id=326
UTF-8 Encoding Trackback URL: http://www.zhenhua.org/trackback.asp?id=326

There is no comment on this article.

If you feel this site you find this information helpful, please click on the donation, which is voluntary,Thank you.
Post Comment
Smilies
[arrow] [biggrin] [confused] [cool]
[cry] [eek] [evil] [exclaim]
[frown] [idea] [lol] [mad]
[mrgreen] [neutral] [question] [razz]
[redface] [rolleyes] [sad] [smile]
[surprised] [twisted] [wink]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password:   Register Now?
Security Code * Please Enter the Security Code