JSP用记事本当数据库验证用户登陆问题

分3个页面

reg.jsp

 <%@ page contentType="text/html;charset=GB2312" %>
<html>
<head>

<title>注册Tootidea涂图计划会员</title>
<link rel="stylesheet" type="text/css" href="tootidea.css" />
<link rel="StyleSheet" href="regcss.css" type="text/css"/>
<style type="text/css">
<!--
.style1 { color: ForestGreen;
 font-size: 14px;
 }
 .style2 { color: red;
 font-size: 14px;
 }
-->
</style>
<script>
 
  ratingMsgs = new Array(6);
  ratingMsgColors = new Array(6);
  barColors = new Array(6);
  ratingMsgs[0] = "太短";
  ratingMsgs[1] = "弱";
  ratingMsgs[2] = "一般";
  ratingMsgs[3] = "很好";
  ratingMsgs[4] = "极佳";
  ratingMsgs[5] = "未评级"; //If the password server is down
  ratingMsgColors[0] = "#676767";
  ratingMsgColors[1] = "#aa0033";
  ratingMsgColors[2] = "#f5ac00";
  ratingMsgColors[3] = "#6699cc";
  ratingMsgColors[4] = "#008000";
  ratingMsgColors[5] = "#676767";
  barColors[0] = "#dddddd";
  barColors[1] = "#aa0033";
  barColors[2] = "#ffcc33";
  barColors[3] = "#6699cc";
  barColors[4] = "#008000";
  barColors[5] = "#676767";
  function CreateRatePasswdReq(pwd) {
    if (!isBrowserCompatible) {
      return;
    }
   
   // if(!document.getElementById) return false;
   // var pwd = document.getElementById("pwd");
    if(!pwd) return false; 
    passwd=pwd.value;
    var min_passwd_len = 3;  //注意这是控制密码长度的
    if (passwd.length < min_passwd_len)  {
      if (passwd.length > 0) {
        DrawBar(0);
      } else {
        ResetBar();
      }
    } else {
     //We need to escape the password now so it won't mess up with length test
       rating = checkPasswdRate(passwd);
       DrawBar(rating);
 
    }
  }
 function getElement(name) {
    if (document.all) {
        return document.all(name);
    }
    return document.getElementById(name);
}
 
  function DrawBar(rating) {
    var posbar = getElement('posBar');
    var negbar = getElement('negBar');
    var passwdRating = getElement('passwdRating');
 
    var barLength = getElement('passwdBar').width;
    if (rating >= 0 && rating <= 4) {  //We successfully got a rating
      posbar.style.width = barLength / 4 * rating + "px";
      negbar.style.width = barLength / 4 * (4 - rating) + "px";
    } else {
      posbar.style.width = "0px";
      negbar.style.width = barLength + "px";
      rating = 5; // Not rated Rating
    }
    posbar.style.background = barColors[rating];
    passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] +
                             "'>" + ratingMsgs[rating] + "</font>";
 
  }
  
  //Resets the password strength bar back to its initial state without any message showing.
  function ResetBar() {
    var posbar = getElement('posBar');
    var negbar = getElement('negBar');
    var passwdRating = getElement('passwdRating');
    var barLength = getElement('passwdBar').width;
    posbar.style.width = "0px";
    negbar.style.width = barLength + "px";
    passwdRating.innerHTML = "";
  }
  /* Checks Browser Compatibility */
  var agt = navigator.userAgent.toLowerCase();
  var is_op = (agt.indexOf("opera") != -1);
  var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
  var is_mac = (agt.indexOf("mac") != -1);
  var is_gk = (agt.indexOf("gecko") != -1);
  var is_sf = (agt.indexOf("safari") != -1);
  function gff(str, pfx) {
    var i = str.indexOf(pfx);
    if (i != -1) {
      var v = parseFloat(str.substring(i + pfx.length));
      if (!isNaN(v)) {
      return v;
      }
    }
    return null;
  }
  function Compatible() {
    if (is_ie && !is_op && !is_mac) {
      var v = gff(agt, "msie ");
      if (v != null) {
        return (v >= 6.0);
      }
    }
    if (is_gk && !is_sf) {
      var v = gff(agt, "rv:");
      if (v != null) {
         return (v >= 1.4);
      } else {
         v = gff(agt, "galeon/");
         if (v != null) {
           return (v >= 1.3);
         }
      }
    }
    if (is_sf) {
      var v = gff(agt, "applewebkit/");
      if (v != null) {
        return (v >= 124);
      }
    }
    return false;
  }
 
  /* We also try to create an xmlhttp object to see if the browser supports it */
  var isBrowserCompatible = Compatible();

//CharMode函数 
//测试某个字符是属于哪一类. 
function CharMode(iN){ 
if (iN>=48 && iN <=57) //数字 
return 1; 
if (iN>=65 && iN <=90) //大写字母 
return 2; 
if (iN>=97 && iN <=122) //小写 
return 4; 
else 
return 8; //特殊字符 

//bitTotal函数 
//计算出当前密码当中一共有多少种模式 
function bitTotal(num){ 
modes=0; 
for (i=0;i<4;i++){ 
if (num & 1) modes++; 
num>>>=1; 

return modes; 

//checkStrong函数 
//返回密码的强度级别 
function checkPasswdRate(sPW){ 
if (sPW.length<=1) 
return 0; //密码太短 
Modes=0; 
for (i=0;i<sPW.length;i++){ 
//测试每一个字符的类别并统计一共有多少种模式. 
Modes|=CharMode(sPW.charCodeAt(i)); 

return bitTotal(Modes); 

 
 </script>
  <script language="JavaScript">
 function Juge()
{  
if (document.getElementById("pwd").value != document.getElementById("Password1").value)
  {
document.getElementById("pwd").focus();
document.getElementById("pwd").value="";
document.getElementById("Password1").value="";
var label = getElement('label');
label.innerHTML="两次密码不对!";
 }
 
}
</script>
 
<script language="javascript" >
function space()
{
var str=document.getElementById("pwd").value;
if (str.indexOf(" ")>0)
{
document.getElementById("pwd").focus();
document.getElementById("pwd").value="";
label.innerHTML="不能输入含空格的密码";
}
else
{
label.innerHTML="    ";

}
}

</script>

</head>

<body>
<form action="reginfo.jsp" method=post name=form>
<div align="center" style="width: 984px; height: 64px">
    <img alt="Tootidea" src="tootidea/tootlogo.jpg" /></div>
<br />
<div id="menu" style="width: 984px; height: 1px" ><ul id="di" align="center" style="width: 296px; height: 16px;">
 <li class="c" ><a href="index.jsp">首页</a> </li>
 <li class="c"><a href="login.jsp">登录</a> </li>
        <li class="c"><a href="reg.jsp">注册</a> </li>
        <li class="c"><a href="shopping.jsp">购物</a> </li>
        <li class="c"><a href="feedback.jsp">留言板</a> </li>
  </ul>
  </div>
 <div align="center">
  <div class="newExist widget">
    <fieldset >
 <p align="left" style="font-size:18px">
        <strong> 注册 Tootidea</strong></p>
    <p align="left">*必填字段
      </p>
    </fieldset>
</div>
<div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
<p align="left" class="style1">
    创建 Tootidea 用户</p>
    <p align="left" >
    *Tootidea 用户:&nbsp;&nbsp;&nbsp;&nbsp;<input name="textfield1" type="text" size="10">
    </p>
</fieldset>  
  </div>
 
    <div  >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
<p align="left" style="font-size:14px; color: ForestGreen">选择您的密码</p>
<p align="left">
<td >*键入密码:</td>
<td>
<input id="pwd1" name="pwd" οnkeyup="CreateRatePasswdReq(this)"; type="password" value="" maxlength=15 οnblur="space(this)" />
 <span style="FONT-FAMILY: arial,sans-serif">长度最多包含15个字符且不能包含空格。</span>
<table cellspacing="0" cellpadding="0" border="0">
<td valign="top" noWrap width="0" style="height: 20px"><font face="Arial, sans-serif" size=-1>
  <P style="font-size:10px ">密码强度:
</font></td>
<td valign="top" noWrap style="height: 20px"><font face="Arial, sans-serif" color="#808080" size="-1"><strong>
<div id="passwdRating"></div>

</strong></font><table id="passwdBar" cellspacing="0" cellpadding="0" width="180" bgColor="#ffffff" border="0">
<td id="posBar" width="0%" bgColor="#e0e0e0" style="height: 12px"></td>
<td id="negBar" width="100%" bgColor="#e0e0e0" style="height: 12px"></td>
</table></td>
<tr>
<td style="height: 4px"></td>
</tr>

</table>
*重新键入密码:<input id="Password1" name="pwd1"  type="password" value=""   οnblur="Juge()" maxlength=15 />
</td>
<div id="label"  class="style2"></div>
</p>
</fieldset>  
</div>
 
 <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
<p align="left" class="style1">
    请填写相关资料</p>
    <p align="left" >
    地址:&nbsp;&nbsp;&nbsp;&nbsp;<input name="textfield3" type="text" size="15">
    </p>
 <p align="left" >
    电话:&nbsp;&nbsp;&nbsp;&nbsp;<input name="textfield4" type="text" size="15">
    </p>
 <p align="left" >
    EMAIL:&nbsp;&nbsp;&nbsp;&nbsp;<input name="textfield5" type="text" size="15" >
    </p>
</fieldset>  
  </div>
<div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
<p align="left" class="style1">
    请确认您的操作</p>
    <p align="left" >
     <input type="submit" name="Submit" value="提交" >
  <input type="reset" name="Submit" value="重置">
  <div id="label1"  class="style2"></div>
    </p>
</fieldset>  
  </div>
 </div>
 
</form>
</body>
</html>

reginfo.jsp

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.io.*" %>
<%@ page import ="java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册信息显示</title>
<link rel="stylesheet" type="text/css" href="tootidea.css" />
  <link rel="StyleSheet" href="regcss.css" type="text/css"/>
  <style type="text/css">
<!--
.style1 {color: #FF0000}
-->
  </style>
</head>

<body>
<div align="center" style="width: 984px; height: 64px">
    <img alt="Tootidea" src="tootidea/tootlogo.jpg" /></div>
<br />
<div id="menu" style="width: 984px; height: 1px" ><ul id="di" align="center" style="width: 296px; height: 16px;">
 <li class="c" ><a href="index.jsp">首页</a> </li>
 <li class="c"><a href="login.jsp">登录</a> </li>
        <li class="c"><a href="reg.jsp">注册</a> </li>
        <li class="c"><a href="shopping.jsp">购物</a> </li>
        <li class="c"><a href="feedback.jsp">留言板</a> </li>
 </ul>
  </div>
  <%
String name=request.getParameter("textfield1");
String mount=request.getParameter("pwd");
String s3=request.getParameter("textfield3");
String s4=request.getParameter("textfield4");
String s5=request.getParameter("textfield5");
session.setAttribute("name",name);
%>
<%!
      Hashtable hashtable=new Hashtable();
      synchronized void putGoodsToHashtable(String key,String list)
        {
           hashtable.put(key,list);
        }
  %>
 <%
    // String name=request.getParameter("n");
    // String mount=request.getParameter("m");
     if(name==null||mount==null)
       {
         name="";
         mount="";
       }
     else
       {
           byte  c[]=name.getBytes("ISO-8859-1");
           name=new String(c);
           byte  d[]=mount.getBytes("ISO-8859-1");
           mount=new String(d);
       }
         
  
   %>

<%
       File f=new File("d:/jsp/103","tttt.txt");
       if(f.exists())
         {
          try{
                FileInputStream in=new FileInputStream(f);
                ObjectInputStream object_in=new ObjectInputStream(in);
                hashtable=(Hashtable)object_in.readObject();
                object_in.close();
                in.close();
                if(hashtable.containsKey(name))
                 {
                   session.setAttribute("name",name);
               
                 }
                else
                 {
                   String s="*"+name+"#"+mount+"*";
                   putGoodsToHashtable(name,s);           //向散列表填加新的货物信息。
                  try{
                         FileOutputStream o=new FileOutputStream(f);
                         ObjectOutputStream object_out=new ObjectOutputStream(o);
                         object_out.writeObject(hashtable);
                         object_out.close();
                         o.close();
                     }
                   catch(Exception eee){}
              
            
                 }
              }
             catch(IOException e) {}
         }   
      else
         {
           String s="*"+name+"#"+mount+"*";
           putGoodsToHashtable(name,s);
           try{
                FileOutputStream o=new FileOutputStream(f);
                ObjectOutputStream object_out=new ObjectOutputStream(o);
                object_out.writeObject(hashtable);
                object_out.close();
                o.close();
             
            
               }
           catch(Exception eee){}
         }
   %>
<div align="center">
<div class="newExist widget">
    <fieldset >
 <p align="left" style="font-size:18px">
        <strong>  Tootidea会员信息</strong></p>
    </fieldset>
</div>

<div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" >
    您的用户名:&nbsp;<%=name%>
    </p>
</fieldset>  
  </div>
  <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" >
    您的密码:&nbsp;<%=mount%>
    </p>
</fieldset>  
  </div>
  <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" >
    您的地址:&nbsp;<%=s3%>
    </p>
</fieldset>  
  </div>
  <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" >
您的电话:&nbsp;<%=s4%>
    </p>
</fieldset>  
  </div>
  <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" >
   您的EMAIL:&nbsp;<%=s5%>
    </p>
</fieldset>  
  </div>
  <br/>
  <br/>
    <div >
<fieldset class="widgetHelp"  bgcolor="#FFFFFF" >
    <p align="left" class="style1" >
   您可以利用导航进行操作,可以马上进行购物体验,留言,练习等。
  
    </p>
</fieldset>  
  </div>
 
</div>
</body>
</html>
puanduan.jsp

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.io.*" %>
<%@ page import ="java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Tootidea货物管理练习</title>
<link rel="stylesheet" type="text/css" href="tootidea.css" />
<link rel="StyleSheet" href="regcss.css" type="text/css"/>
</head>

<body>
<%


String a=request.getParameter("textfield");
 String b=request.getParameter("textfield1");

//String a=request.getParameter("a");
  //   String b=request.getParameter("b");   
String c=a+"#"+b;
String d="";
int i=0;
  try{
          File f=new File("d:/jsp/103","tttt.txt");
          FileInputStream in=new FileInputStream(f);
          ObjectInputStream object_in=new ObjectInputStream(in);
          Hashtable  hashtable=(Hashtable)object_in.readObject();
          object_in.close();
          in.close();
          Enumeration enum1=hashtable.elements(); //enum是关键字不能作变量使用
       
           while(enum1.hasMoreElements())   //遍历当前散列表。
             {
            
                String goods=(String)enum1.nextElement();
                StringTokenizer fenxi=new StringTokenizer(goods,"*");
                while(fenxi.hasMoreTokens())
                  {
                   String str=fenxi.nextToken();
           
i++;
   if (c.equals(str))
    {
    d="ok";
   if (d.equals("ok"))
     {
     
response.sendRedirect("denglu.jsp");
     }

    }
                  }  
   }out.print(i);//用户不存在
if(i!=0)
{
response.sendRedirect("reg.jsp");
}
         
           hashtable.clear();
         }
     catch(Exception event)
         {
out.println("没有这个用户哦!");
         }
   %>
 

  <a href="reg.jsp">马上去注册</a>

</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值