验证码

原创
2014/05/14 18:34
阅读数 83
用户注册加入验证码
从同事那弄过来,拿来主义了.
 
用到一个jar包(附件里有)
jsp测试页:
< %@ page contentType ="text/html; charset=GBK" % >
< %@ page import = "cn.com.enorth.util.imgcode.ImageCodeUtils" % >
<%
String txt = "";
String rightCode = ImageCodeUtils.getCodeValue(request);
if(ImageCodeUtils.isGoodCode(request,"thecode")){
    txt="yes";
}
else{
    txt="no";
}
%>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" />
< title >test image code </title>
< script language ="javascript" >
function reloadImg(){
var i = Math.random();
document.getElementById("imgCode").src="imgcode?"+i;
}
</script>
</head>
< body bgcolor ="#ffffff" >
< form action ="test.jsp" method ="POST" name ="form1" >
     < img id ="imgCode" src ="imgcode" border ="0" >
     < input type ="text" name ="thecode" />     < a href ="javascript:reloadImg();" >看不清? </a>
     < br >
     < input type ="submit" name ="submit" value ="submit" />     < %=txt% >
</form>
< a href ="changetype.jsp" >change type </a>
</body>
</html>
 
自己的用法:
页面
< tr >
       < td width ="30%" align ="right" >
         < img id ="imgCode" src ="imgcode" border ="0" />
       </td>
       < td >
             < input type ="text" name ="thecode" /> < font color ="red" >* </font>
             < a href ="javascript:reloadImg();" >看不清? </a>
             < font color ="red" >${VerificationError } </font>
       </td>
     </tr>
 
程序中(如果验证码输入正确...)
if (ImageCodeUtils.isGoodCode(request, "thecode")){
     ...
     ...
     return SUCCESS;
}
 
 

本文出自 “wIsper 把技术做成艺术” 博客,请务必保留此出处http://lichen.blog.51cto.com/697816/140783

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部