源代码下载地址:http://www.zuidaima.com/share/1724427578084352.htm
1.验证码 -- 平台项目帐号登录时常用到的,有一定安全防范君子的报障,可防范没有什么技术小人呵呵,开玩笑不要认真,可能对初学者有帮助,有需要拿去吧
2.配置,主要是web.xml的配置,如下:
1 |
< servlet >
|
2 |
< servlet-name >RandomCode</ servlet-name >
|
3 |
< servlet-class >com.zuidaima.servlet.RandomCode</ servlet-class >
|
4 |
</ servlet >
|
5 |
< servlet-mapping >
|
6 |
< servlet-name >RandomCode</ servlet-name >
|
7 |
< url-pattern >/randomCode</ url-pattern >
|
8 |
</ servlet-mapping >
|
3.代码调用部门实现如下:
01 |
< body >
|
02 |
< iframe src = "/randomCode" id = "codeFrame" name = "codeFrame" frameborder = "no" border = "0" marginwidth = "0"
|
03 |
marginheight = "0" scrolling = "no" allowtransparency = "yes" height = "35" width = "102" ></ iframe >
|
04 |
< a href = "javascript:void(0);" onclick = "refreshCode();" >refresh</ a >
|
05 |
< br >
|
06 |
< span id = "codeImg" >< img border = 0 src = "randomCode" ></ span >
|
07 |
< a href = "javascript:void(0);" onclick = "reloadCode()" > try times</ a >
|
08 |
</ body >
|
09 |
< script type = "text/javascript" >
|
10 |
function $(id){
|
11 |
return document.getElementById(id);
|
12 |
}
|
13 |
|
14 |
/**刷新iframe**/
|
15 |
function refreshCode(){
|
16 |
window.frames["codeFrame"].location.reload();
|
17 |
}
|
18 |
|
19 |
/**替换图片**/
|
20 |
function reloadCode(){
|
21 |
$("codeImg").innerHTML = "< img border = 0 src = 'randomCode' >";
|
22 |
}
|
23 |
</ script >
|
4、上项目结构图:
5、运行效果图