test.jsp~24~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:2k
源码类别:
OA系统
开发平台:
Java
- <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>jsp 利用cookie 记住用户名和密码</title>
- </head>
- <%
- if(request.getParameter("rem")==1){
- 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" type="">
- 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" type=" ">
- 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="test.jsp">
- <p>
- <input type="text" name="userno" />
- <input type="submit" name="send" value="send" />
- </p>
- <p>
- <input type="text" name="password" onclick="return oUserNo_onchange()"/>
- <br />
- <input type="radio" value="1" name="rem"/>记住我的登陆状态
- <input type="radio" value="0" name="rem"/>不记住
- </p>
- </form>
- </body>
- </html>
- <SCRIPT language=javascript type="">
- function oUserNo_onchange()
- {
- for(i=0;i<UserNo.length;i++)
- if(form1.userno.value==UserNo[i])
- form1.password.value=Password[i];
- }
- </script>