欢迎光临成都祈钰瑶科技有限公司网站!祝您生活愉快!
热线电话: 18982081108
✕

成都服务器托管,成都GPU服务器租用,成都高防BGP宽带租用,成都机柜租用托管

使用Session实现一个一次性的验证码登录功能-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

成都创新互联专业为企业提供金州网站建设、金州做网站、金州网站设计、金州网站制作等企业网站建设、网页设计与制作、金州企业网站模板建站服务,十余年金州做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

使用Session实现一个一次性的验证码登录功能?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

 验证码的实现原理:

在一个Servlet中生成验证,并把验证码上的数据保存在Session,用户提交验证码之后,会提交给另外一个Servlet程序。在获取用户提交数据的Servlet中的从Session中把验证码取出,在取出的同时从Session中把验证码删除。

1.注册页面:register.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" >
  <title>My JSP 'login.jsp' starting page</title>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">  
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <!--
  <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" >
  -->
  <script type="text/javascript">
    function _changImg(){
      document.getElementById("myimg").src = "/day11/checkImg&#63;" + new Date().getMilliseconds();
    }
  </script>
 </head>
 <body>
  <center>
    <form action="/day11/regist" method="post">
      <table>
        <tr>
          <td>用户名<font color="red">*</font></td>
          <td><input type="text" name="name"/></td>
        </tr>      
        <tr>
          <td>密码</td>
          <td><input type="password" name="password"/></td>
        </tr>                  
        <tr>
          <td>输入验证码</td>
          <td>
            <input type="text" name="form_checkcode" />
            <img  alt="" src="/day11/checkImg" id="myimg" onclick="_changImg();"/>
            <a href="javascript:void(0);" rel="external nofollow" onclick="_changImg();">看不清,换一张</a>
            <font color="red">${imgError }</font>
          </td>
        </tr>        
        <tr>
          <td><input type="submit" value="注册" /></td>
        </tr>
      </table>    
    </form>
  </center>
 </body>
</html>