<%@ 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++) { ?//根據(jù)cookie的名字進行篩選 if("username_cook".equals(cookies[i].getName())) { ?//使用前注意要轉(zhuǎn)碼(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("請?zhí)顚懹脩裘?); document.getElementById("uNameId").focus(); return ; } if(password=="") { alert("請?zhí)顚懹脩裘?); document.getElementById("uPassId").focus(); return ; } sf ?= document.getElementById("sf").value; checkUser(userName,password,sf); } ? ? function checkUser(userName,password,sf) ? ? { ? ? ? var xmlhttp = null; ? ? ? ? ? ? //1、固定創(chuàng)建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()三個參數(shù)是可變 ? ? ? xmlhttp.open("post",url,true);///三個參數(shù)..第一個請求方式 第二個地址 ?第三個是否異步(boolean) ? ? ? xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");? ? ? ? //發(fā)送請求 ? ? ? 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正常返回頁面 ? ? ? ? ? ? //接收回調(diào)函數(shù)的返回值 ? ? ? 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" <%} %>>學(xué)生</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>
button無法點擊
泡芙公主果果
2015-04-29 14:12:00