test.jsp~24~
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:2k
源码类别:

OA系统

开发平台:

Java

  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>jsp 利用cookie 记住用户名和密码</title>
  6. </head>
  7. <%
  8. if(request.getParameter("rem")==1){
  9. Cookie cookie=new Cookie(request.getParameter("userno"), request.getParameter("password"));
  10. cookie.setMaxAge(360*24*60*60);
  11. response.addCookie(cookie);
  12. }
  13. Cookie cookies[]=request.getCookies();
  14. Cookie sCookie=null;
  15. String svalue=null;
  16. String sname=null;
  17. %>
  18. <script language="javascript" type="">
  19. var UserNo=new Array(); UserNo[0]="";
  20. var Password=new Array(); Password[0]="";
  21. </script>
  22. <%
  23. for(int i=0;i<cookies.length;i++){
  24. sCookie=cookies[i];
  25. %>
  26. <script language="javascript" type=" ">
  27. UserNo[<%=i%>]="<%=sCookie.getName()%>";
  28. Password[<%=i%>]="<%=sCookie.getValue()%>";
  29. </script>
  30. <%
  31. out.print(sCookie.getName()+"      "+sCookie.getValue()+"</br>");
  32. }
  33. %>
  34. <body>
  35. <form id="form1" name="form1" method="post" action="test.jsp">
  36.       <p>
  37.         <input type="text" name="userno" />
  38.         <input type="submit" name="send" value="send" />
  39.       </p>
  40.       <p>
  41.         <input type="text" name="password" onclick="return oUserNo_onchange()"/>
  42.         <br />
  43.         <input type="radio" value="1" name="rem"/>记住我的登陆状态
  44.         <input type="radio" value="0" name="rem"/>不记住
  45. </p>
  46. </form>
  47. </body>
  48. </html>
  49. <SCRIPT language=javascript type="">
  50. function oUserNo_onchange()
  51. {
  52. for(i=0;i<UserNo.length;i++)
  53.        if(form1.userno.value==UserNo[i])
  54.         form1.password.value=Password[i];
  55. }
  56. </script>