怎么判断验证码输入的值和session中的值是否相等呢?一个是表单提交的,一个是session中的<script language="javascript">
function check() {
var code = document.getElementsByName("session").value;
var input = document.getElementsByName("code").value;
if(code != input) {
alert("验证码不正确");
return false;
} else {
return true;
}
}
</script><form action="index.jsp" method="post"><input type="hidden" name="session" value="<%=session.getAttribute("zaokurand").toString()%>" />
<div>
验证码:<input style="HEIGHT: 18px" size="8" maxlength="4" type="text" name="code" id="code" />
<span id="rand_img" style="display:block;"> </span>
<input type="button" id="button" value="提交" onclick="return check();"/>
</div>
</form>
function check() {
var code = document.getElementsByName("session").value;
var input = document.getElementsByName("code").value;
if(code != input) {
alert("验证码不正确");
return false;
} else {
return true;
}
}
</script><form action="index.jsp" method="post"><input type="hidden" name="session" value="<%=session.getAttribute("zaokurand").toString()%>" />
<div>
验证码:<input style="HEIGHT: 18px" size="8" maxlength="4" type="text" name="code" id="code" />
<span id="rand_img" style="display:block;"> </span>
<input type="button" id="button" value="提交" onclick="return check();"/>
</div>
</form>
解决方案 »
- 第六十行错误怎么回事
- java配置文件
- netbean开发j2ee需要安装什么,如何配置?
- b/s公交查询系统 hql(站站,站点查询)语句写不来了,总是报错,求救。。。
- 用户登陆 为什么tomcat报错
- 谁能讲解一下structs的例子:http://localhost:8080/struts-examples/exercise/bean-write-2.do
- Serlet + Apache2 + resin-2.1.9
- 一个发送字符的问题
- 急急,要使用TOMCAT自带的数据连接池,但不想将数据库的帐号和密码放到配置文件,而是写到程序中
- 内存中染上病毒该咋办!!!
- 在服务器中执行和单独执行New File()方法,来判断一个文件是否存在的区别?
- 如何设置FormFile对象为空值
改成
<input type="hidden" name="session" value="<%=request.getSession().getAttribute("zaokurand").toString()%>" />
试试看
<script language="javascript">
function check() {
var code = document.getElementsByName("session").value;//断点1
var input = document.getElementsByName("code").value;//断点2
if(code != input) {
alert("验证码不正确");
return false;
} else {
return true;
}
}
</script>
用F12键查看一下code 和input的值