jsp 利用cookie 记住用户名和密码

<% @page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage=""  %>
< html >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GBK"   />
< title > jsp 利用cookie 记住用户名和密码 </ title >
</ head >
<%
if(request.getParameter("send")!=null)
{

Cookie cookie
=new Cookie(request.getParameter("userno"), request.getParameter("password")); 
cookie.setMaxAge(
360*24*60*60); 
response.addCookie(cookie); 

}
Cookie cookies[]
=request.getCookies(); 
Cookie sCookie
=null
String svalue=null
String sname=null
%>
< script  language ="javascript" >
var UserNo=new Array(); UserNo[0]="";
var Password=new Array(); Password[0]="";
</ script >
<%
for(int i=0;i<cookies.length;i++){ 
sCookie
=cookies[i]; 
%>
< script  language ="javascript" >
UserNo[
<%=i%>]="<%=sCookie.getName()%>";
Password[
<%=i%>]="<%=sCookie.getValue()%>"
</ script >
<%
out.print(sCookie.getName()
+"      "+sCookie.getValue()+"</br>");
}
%>
< body >
< form  id ="form1"  name ="form1"  method ="post"  action ="" >
      
< p >
        
< input  type ="text"  name ="userno"   />
        
< input  type ="submit"  name ="send"  value ="s"   />
      
</ p >
      
< p >
        
< input  type ="text"  name ="password"  onclick ="return oUserNo_onchange()" />
</ p >
</ form >
</ body >
</ html >
< SCRIPT  language =javascript >
function oUserNo_onchange(){  
    
for(i=0;i<UserNo.length;i++)
       
if(form1.userno.value==UserNo[i])
        form1.password.value
=Password[i];
}
  
</ script >
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值