test.jsp~27~
上传用户: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")!=null)
  9. if(request.getParameter("rem").equals("1")){
  10. Cookie cookie=new Cookie(request.getParameter("userno"), request.getParameter("password"));
  11. cookie.setMaxAge(360*24*60*60);
  12. response.addCookie(cookie);
  13. }
  14. Cookie cookies[]=request.getCookies();
  15. Cookie sCookie=null;
  16. String svalue=null;
  17. String sname=null;
  18. %>
  19. <script language="javascript" type="">
  20. var UserNo=new Array(); UserNo[0]="";
  21. var Password=new Array(); Password[0]="";
  22. </script>
  23. <%
  24. for(int i=0;i<cookies.length;i++){
  25. sCookie=cookies[i];
  26. %>
  27. <script language="javascript" type=" ">
  28. UserNo[<%=i%>]="<%=sCookie.getName()%>";
  29. Password[<%=i%>]="<%=sCookie.getValue()%>";
  30. </script>
  31. <%
  32. out.print(sCookie.getName()+"      "+sCookie.getValue()+"</br>");
  33. }
  34. %>
  35. <body>
  36. <form id="form1" name="form1" method="post" action="test.jsp">
  37.       <p>
  38.         <input type="text" name="userno" />
  39.         <input type="submit" name="send" value="send" />
  40.       </p>
  41.       <p>
  42.         <input type="text" name="password" onclick="return oUserNo_onchange()"/>
  43.         <br />
  44.         <input type="radio" value="1" name="rem" checked="checked"/>记住我的登陆状态
  45.         <input type="radio" value="0" name="rem"/>不记住
  46. </p>
  47. </form>
  48. </body>
  49. </html>
  50. <SCRIPT language=javascript type="">
  51. function oUserNo_onchange()
  52. {
  53. for(i=0;i<UserNo.length;i++)
  54.        if(form1.userno.value==UserNo[i])
  55.         form1.password.value=Password[i];
  56. }
  57. </script>