日期:2014-05-16 浏览次数:20706 次
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function btn_click(){
//创建XMLHttpRequest对象
var xmlHttp;
xmlHttp=new XMLHttpRequest();
try{
//兼容Firefox,Opera8.0+,Safari
xmlHttp=new XMLHttpRequest();
}catch(e){
//兼容IE
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持ajax");
return false;
}
}
}
//获取文本框的值
var username=document.getElementById("txt_username").value;
var password=document.getElementById("txt_password").value;
//设置编码,避免中文出现乱码。
username=encodeURIComponent(encodeURIComponent(username));
//配置XMLHttpRequest对象
xmlHttp.open("GET","servlet/LoginServlet?username="+username+"&password="+password,true);
//设置回调函数
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==0){
docuement.getElementById("result").innerHTML="未初始化.还没调用open()..";
}else if(xmlHttp.readyState==1){
docuement.getElementById("result").innerHTML="正在连接服务器.还没调用send()..";
}else if(xmlHttp.readyState==2){
docuement.getElementById("result").innerHTML="正在加载信息...";
}else if(xmlHttp.readyState==3){
docuement.getElementById("result").innerHTML="正在连收数据...";
}else if(xmlHttp.readyState==4){//表示交互完毕
if(xmlHttp.status==200){//200对应ok ,
document.getElementById("result").innerHTML=xmlHttp.responseText;
}else{
docuement.getElementById(&qu