jsp中添加验证码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>提交表单时加入验证码</title>
</head>
<body>
      <form name="form1" action="check3" method="post">     <!-- 定义form表单 -->
            <table width="300" height="160" border="0" align="center" cellpadding="0" cellspacing="0">
                   
                   
                   <tr>
                       <td height="40" valign="bottom">用户名: <input name="USERNAME" type="text" class="input2"
                       onKeyDown="if(event.keyCode==13){form1.PWD.focus();}"
                       onMouseOver="this.style.background='#F0DAF3';"
                       onMouseOut="this.style.background='#FFFFFF'"/>
                       </td>     <!-- 设置用户名文本框,并设置了鼠标经过时的样式 -->               
                   </tr>
                   
                   
                   <tr>
                       <td height="40" colspan="2" valign="bottom" class="STYLE15">密  码:
                          
                       <input name="PWD" type="password" class="inout2" align="bottom"
                       onKeyDown="if(event.ketCode==13){form1.yanzhengfocus();}"
                       onMouseOver="this.style.background='#F0DAF3';"
                       onMouseOut="this.style.background='#FFFFFF';"/>       <!-- 设置密码我文本框 -->
                       </td>
                   </tr>
                 
                 
                   <tr>
                       <td height="40" colspan="2" valign="top" class="STYLE15"
                       οndragstart="return flase" οnselect="return flase">验证码:
                       <input name="yanzheng" type="text" class="input2"
                       onkeyDown="if(event.keyCode==13){form1.submit.focus();}"
                       size="8" align="bottom"
                       onMouseOver="this.style.background='#F0DAF3';"
                       onMouseOut="this.style.background='#FFFFFF';"/>     <!-- 设置验证码验证框 -->
                       <%
                         int intmethod1=(int)((Math.random()*10)-1);
                         int intmethod2=(int)((Math.random()*10)-1);
                         int intmethod3=(int)((Math.random()*10)-1);
                         int intmethod4=(int)((Math.random()*10)-1);
                         String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4;
                       %>
                       <input type="hidden" name="verifycode" value="<%=intsum%>"/>    <!-- 设置隐藏域,用来验证比较 -->
                       <span class="STYLE15"><font size="+3" color="#FF0000">
                       <img src="num/<%=intmethod1%>.jpg">                   <!--将图片的文件夹放在webContent文件夹下  --> 
                       <img src="num/<%=intmethod2%>.jpg">
                       <img src="num/<%=intmethod3%>.jpg">
                       <img src="num\<%=intmethod4%>.jpg"></font></span>
                       </td>
                   </tr>
                   <tr>
                       <td height="40" colspan="2" valign="bottom" align="center">    
                       <input name="submit" type="button" class="submit1" value="登录" onClick="mycheck"/>
                       <input name="submit2" type="reset" class="submit1" value="重置"/>
                       </td>     <!-- 设置提交于重置按钮 -->
                   </tr>      
            </table>
      </form>
</body>
</html>
其中把数字图片裁剪为20px   放在webContent下的新建num文件夹下  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值