用户注册加入验证码
从同事那弄过来,拿来主义了.
用到一个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; }
本文出自 “” 博客,请务必保留此出处