验证码

用户注册加入验证码
从同事那弄过来,拿来主义了.
 
用到一个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

转载于:https://my.oschina.net/lichen/blog/264930

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值