jsp验证码刷新

来源:互联网 发布:杨辉三角java代码 编辑:程序博客网 时间:2024/05/01 15:24

1.验证码图片标签:

<img alt="验证码" name="validateCodeImg" id="validateCodeImg" src="${rootPath}/validateCode"   onclick="refreshCode()" width="56" height="20" /> 

2.验证码刷新js

   <script type="text/javascript">

function refreshCode() {
document.getElementById("validateCodeImg").src="${rootPath}/validateCode?Math.random()";
}
//在请求后面添加Math.random(),让图片刷新成功

</script>


3.在首次加载验证码的页面,为body添加onload事件,更新验证码,要不然会导致第一次的检验验证码时,从session中获取的验证码为null,导致验证码验证失败

<body onload="refreshCode()">