自己写的一个在登陆时写入cookie


<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib uri="/tag/eoms-taglib" prefix="eoms"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ page import="com.langchao.comm.authority.ResponseMessageObj" %>
<%
//language处理
com.inspur.eoms.common.user.UserSession.invalidate(request);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><eoms:message id="Login" /></title>
<eoms:style file="style.css"/>

<script>
//top location to login.
if(window.top!=window.parent){
window.top.location.href="<c:out value='${pageContext.request.contextPath}'/>";
}
<%
String lang = com.inspur.eoms.common.user.UserSession.getLanguagePrefernce(request);
if("login".equals(request.getParameter("action"))){
ResponseMessageObj loginError=(ResponseMessageObj) request.getAttribute("LoginError");
out.println("alert('"+loginError.getMessage()+"');");
}
%>
</script>

</head>

<body class="userlogin_background">
<form name="form1" action="<c:out value='${pageContext.request.contextPath}'/>/CtrlUser.action?action=login&surl=jsp/home/main.jsp&furl=jsp/login.jsp" method="post">
<table cellspacing="0" cellpadding="0" align="center" style="width:609px; height:100%; border:0;">
 <tr>
   <td valign="middle">
<input type="hidden" name="hName" value="${cookie['eomsname'].value}"/>
<table border="0" cellspacing="6" cellpadding="0" align="center" style="font-size:12px; color:#003399; margin-top:130px;">
 <tr>
<td width="119" style="font-size:14px; font-weight:bold; letter-spacing:4px; text-align:right; color:#fff;">帐号</td>
<td width="209" height="43"><input input name="useraccount" type="text" value="" desc="<eoms:message id="username" />" required style="width:200px; height:26px; background:#fff; " /></td>
 </tr>
 <tr>
<td align="right" style="font-size:14px; font-weight:bold; letter-spacing:4px; text-align:right; color:#fff;">密码</td>
<td height="43"><input name="password" type="password" value="" desc="<eoms:message id="password" />" required style="width:200px; height:26px;; background:#fff;" /></td>
 </tr>
 <tr>
<td></td>
<td valign="bottom" ><input class="btn_submit" name="tijiao" type="button" value="" Onclick="danji()"/> &nbsp;&nbsp;<input class="btn_reset" name="reset" type="reset" value="" /></td>
 </tr>
</table>
<div style="height:25px; color:#000; font-size:12px; width:100%; text-align:center; margin-top:100px;"></div>

</td>
 </tr>
</table>
</form>
</body>
<script language="javascript">

//当点击提交按钮的时候将用户名的信息写入cookie中,第二次登陆自动加载cookie中的信息
function danji(){
var name1;
var pwd1;
var exp;
var value;
var resu;
var cook1=document.getElementById("hName").value;
if(cook1==null || cook1==""){
name1=document.getElementById("useraccount").value;
pwd1=document.getElementById("password").value;
   exp  = new Date();
           exp.setTime(exp.getTime() + 4*60*60*1000);
           value=name1+"-fdasf-"+pwd1;
           resu="eomsname="+escape (value)+";expires="+exp.toGMTString();
document.cookie = resu;
}else{
var cook=document.getElementById("hName").value;
if(cook!=null&&cook!=""){
var brands = new Array();
brands = cook.split("-");
var newuser=document.form1.useraccount.value;
if(newuser!=brands[0]){
name1=document.getElementById("useraccount").value;
pwd1=document.getElementById("password").value;
      exp  = new Date();
           exp.setTime(exp.getTime() + 4*60*60*1000);
           value=name1+"-fdasf-"+pwd1;
           resu="eomsname="+escape (value)+";expires="+exp.toGMTString();
document.cookie = resu;
}
}
}
document.form1.submit();
}
function refer(){
var cook=document.getElementById("hName").value;
if(cook!=null&&cook!=""){
var brands = new Array();
brands = cook.split("-");
document.form1.useraccount.value=brands[0];
document.form1.password.value=brands[2];
}
}
refer();
</script>
</html>


你可能感兴趣的:(web开发,cookie)