js读写cookie,保存用户名和密码
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %> <head><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /><title></title><link href="./pages/ipic/css/main.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="./pages/ipic/scripts/login.js"></script><style type="text/css"><!--body { margin: 0px auto; background-image: url(./pages/ipic/images/bg.jpg); text-align: center; background-repeat: repeat-x; background-color: #FFF;}.foot { color: #666;}--></style><script type="text/javascript">function onLoginLoaded(){if(isPostBack == "False") {GetLastUser(); } } function GetLastUser() {var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67"; var usr = GetCookie(id); if(usr != null) { document.getElementById('username').value = usr;}else {document.getElementById('username').value = "001"; } GetPwdAndChk();} function SetPwdAndChk() { var usr = document.getElementById('username').value; SetLastUser(usr); if(document.getElementById('chkRememberPwd').checked == true) { var pwd = document.getElementById('password').value; var expdate = new Date(); expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); SetCookie(usr,pwd, expdate); }else{ ResetCookie(); } } function SetLastUser(usr) { var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67"; var expdate = new Date(); expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); SetCookie(id, usr, expdate); } function GetPwdAndChk() { var usr = document.getElementById('username').value; var pwd = GetCookie(usr); if(pwd != null) { document.getElementById('chkRememberPwd').checked = true; document.getElementById('password').value = pwd; } else { document.getElementById('chkRememberPwd').checked = false; document.getElementById('password').value = ""; } } function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; //alert(j); if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var isPostBack = "true"; function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } function SetCookie(name, value, expires) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } function ResetCookie() { var usr = document.getElementById('username').value; var expdate = new Date(); SetCookie(usr, null, expdate); }</script></head><body onload="onLoginLoaded();"><form id="form1" action="./login.do?method=login" method="post"><table width="1010" border="0" cellpadding="0" cellspacing="0"> <tr> <td><table width="1010" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="322"><img src="./pages/sata/images/login_12_01.jpg" width="322" height="85" alt="js读写cookie,保留用户名和密码" /></td> <td width="322"><img src="./pages/sata/images/login_12_02.jpg" width="322" height="85" alt="js读写cookie,保留用户名和密码" /></td> <td width="252"><img src="./pages/sata/images/login_12_03.jpg" width="252" height="85" alt="js读写cookie,保留用户名和密码" /></td> <td><img src="./pages/sata/images/login_12_04.jpg" width="114" height="85" alt="js读写cookie,保留用户名和密码" /></td> </tr> </table></td> </tr> <tr> <td><table width="1010" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="322"><img src="./pages/sata/images/login_12_05.jpg" width="322" height="90" alt="js读写cookie,保留用户名和密码" /></td> <td width="322"><img src="./pages/sata/images/login_12_06.jpg" width="322" height="90" alt="js读写cookie,保留用户名和密码" /></td> <td width="252"><img src="./pages/sata/images/login_07.jpg" width="252" height="90" alt="js读写cookie,保留用户名和密码" /></td> <td><img src="./pages/sata/images/login_12_08.jpg" width="114" height="90" alt="js读写cookie,保留用户名和密码" /></td> </tr> </table></td> </tr> <tr> <td><table width="1010" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="322"><img src="./pages/sata/images/login_12_09.jpg" width="322" height="112" alt="js读写cookie,保留用户名和密码" /></td> <td width="322"><img src="./pages/sata/images/login_12_10.jpg" width="322" height="112" alt="js读写cookie,保留用户名和密码" /></td> <td width="252" align="center" background="./pages/sata/images/login_11.jpg"><table width="90%" height="95" border="0" cellpadding="0" cellspacing="0"> <tr> <td><html:errors/></td> </tr> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="40%">用户名:</td> <td width="60%"><input type="text" name="username" value="${loginform.username }" style="height:18px; width: 150px;" onblur="GetPwdAndChk();" onkeydown="javascript:doLogin();"/></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="40%">密 码:</td> <td width="60%"> <input type="password" name="password" style="height:18px; width: 150px;" onkeydown="javascript:doLogin();"/> </td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <input type="checkbox" name="chkRememberPwd" checked="checked"/>记住密码 </td> </tr> </table></td> </tr> <tr> <td align="center"><table width="164" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="79"><img src="./pages/sata/images/login_butt1.jpg" width="79" height="27" border="0" onmouseover="changeimg(this,'./pages/sata/images/login_butt10.jpg')" onmouseout="changeimg(this,'./pages/sata/images/login_butt1.jpg')" onclick="login()" style="cursor:pointer;"/></td> <td width="6"></td> <td width="79"><img src="./pages/sata/images/login_butt2.jpg" width="79" height="27" border="0" onclick="setN('username','password')" onmouseover="changeimg(this,'./pages/sata/images/login_butt20.jpg')" onmouseout="changeimg(this,'./pages/sata/images/login_butt2.jpg')" style="cursor:pointer;"/></td> <td> </td> </tr> </table></td> </tr> </table></td> <td><img src="./pages/sata/images/login_12_12.jpg" width="114" height="112" alt="js读写cookie,保留用户名和密码" /></td> </tr> </table></td> </tr> </body></html>