<%@ page language="java" pageEncoding="utf-8" isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>登陆页面</title>
<%
//在cookie中查找用户名密码
//通过request得到全部cookie
Cookie[] cookies = request.getCookies();
String user = "";
String password ="";
String sf="";
if(cookies != null)
{
// 使用指定的编码机制对 application/x-www-form-urlencoded 字符串解码。
for(int i=0;i<cookies.length;i++)
{ //根据cookie的名字进行筛选
if("username_cook".equals(cookies[i].getName()))
{ //使用前注意要转码(URLDecoder.decode)
user=java.net.URLDecoder.decode(cookies[i].getValue(),"utf-8");
}
if("userpass_cook".equals(cookies[i].getName()))
{
password=java.net.URLDecoder.decode(cookies[i].getValue(),"utf-8");
}
if("usersf_cook".equals(cookies[i].getName()))
{
sf=cookies[i].getValue();
}
}
}
System.out.println("user:"+user+" password:"+password+" sf:"+sf);
%>
<!-- script type="text/javascript" src="/WebStudents/script/login.js"></script-->
<link rel="stylesheet" href="<%=request.getContextPath() %>/css/base.css" type="text/css"></link>
<SCRIPT LANGUAGE="JavaScript">
function login()
{
//获得用户名
userName = document.getElementById("uNameId").value;
//获得密码
password = document.getElementById("uPassId").value;
if(userName=="")
{
alert("请填写用户名!");
document.getElementById("uNameId").focus();
return ;
}
if(password=="")
{
alert("请填写用户名!");
document.getElementById("uPassId").focus();
return ;
}
sf = document.getElementById("sf").value;
checkUser(userName,password,sf);
}
function checkUser(userName,password,sf)
{
var xmlhttp = null;
//1、固定创建XMLHttpRequest对象
if(window.XMLHttpRequest){
//ie7++
xmlhttp = new XMLHttpRequest();
}else{
//以下版本
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//ie6以下 - XMLHTTP
}
var url = "<%=request.getContextPath()%>/CheckUser";
//2、open() sened()一定要有 //如果向后台传值xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//1.2 open()三个参数是可变
xmlhttp.open("post",url,true);///三个参数..第一个请求方式 第二个地址 第三个是否异步(boolean)
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//发送请求
xmlhttp.send("username="+userName+"&"+"password="+password+"&sf="+sf);
//3、回参它是固定的//0 (未初始化) 1 (正在装载) 2 (装载完毕) 3 (交互中) 4 (完成)
xmlhttp.onreadystatechange = function (){
//4、这块基本固定
if(xmlhttp.readyState == 4 && xmlhttp.status == "200"){//200正常返回页面
//接收回调函数的返回值
var checkresult = xmlhttp.responseText;
if("true"==checkresult)
{
document.getElementById("thisForm").submit();
}
else
{
alert("用户名密码错误!");
document.getElementById("uNameId").focus();
document.getElementById("uNameId").select();
}
}
}
}
</SCRIPT>
</head>
<body class="loginBody">
<form method="POST" action="<%= request.getContextPath()%>/login" id="thisForm">
<table align="center" height="100%" cellspacing = "0" cellpadding = "0">
<tr>
<td><img src="<%=path %>/image/2769387.png"/></td>
</tr>
<tr>
<td>
<table align="center" width="100%" height="100%" cellspacing = "0" cellpadding = "0">
<tr>
<td align="center" valign="middle">
<table>
<tr>
<td>用户</td>
<td>
<input type="text" name="uName" id="uNameId" value="<%=user %>"/>
</td>
</tr>
<tr>
<td>密码</td>
<td>
<input type="password" name="uPass" id="uPassId" value="<%=password %>"/>
</td>
</tr>
<tr>
<td>身份</td>
<td>
<select name="sf" id="sf">
<option value="student" <%if(sf.equals("student")){%>selected="selected" <%} %>>学生</option>
<option value="teacher" <%if(sf.equals("teacher")){%>selected="selected" <%} %>>老师</option>
<option value="dba" <%if(sf.equals("dba")){%>selected="selected" <%} %>>管理员</option>
</select>
</td>
</tr>
<tr>
<td>保存登录信息</td>
<td>
<select name="saveInfo" >
<option value="noSave">不保存信息</option>
<option value="${24*60*60 }">一天</option>
<option value="${24*60*60*7 }">一周</option>
<option value="${24*60*60*30}">一月</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="登陆" id="log" onclick="login()"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
慕郎_莲华
相关分类