⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.jsp

📁 Ajax 本教程介绍了jsp中实现Ajax技术
💻 JSP
字号:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
	<META http-equiv=Content-Type content="text/html; charset=UTF-8">
</head>
<script language="javascript">
	var XMLHttpReq = false;
 	//创建XMLHttpRequest对象       
    function createXMLHttpRequest() {
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			XMLHttpReq = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	}
	//发送请求函数
	function sendRequest(url) {
		createXMLHttpRequest();
		XMLHttpReq.open("GET", url, true);
		XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
		XMLHttpReq.send(null);  // 发送请求
	}
	// 处理返回信息函数
    function processResponse() {
    	if (XMLHttpReq.readyState == 4) { // 判断对象状态
        	if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
            	var res=XMLHttpReq.responseXML.getElementsByTagName("res")[0].firstChild.data;
                window.alert(res);                
            } else { //页面不正常
                window.alert("您所请求的页面有异常。");
            }
        }
    }
	// 身份验证函数
    function userCheck() {
		var uname = document.myform.uname.value;
		var psw = document.myform.psw.value;
		if(uname=="") {
			window.alert("用户名不能为空。");
			document.myform.uname.focus();
			return false;
		}
		else {
			sendRequest('login?uname='+ uname + '&psw=' + psw);
		}
}

</script>

<body vLink="#006666" link="#003366" bgColor="#E0F0F8">
<img height="33" src="enter.gif" width="148">
<form action="" method="post" name="myform">
用户名: <input size="15" name="uname"><p>
密&nbsp;&nbsp;码: <input type="password" size="15" name="psw"><p>
<input type="button" value="登录" onclick="userCheck()" >
</form>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -