index.jsp
<%@ page contentType="text/html; charset=gbk"%><br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br /> <html><br /> <head><br /> <title>Check.html</title></p><p> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><br /> <meta http-equiv="description" content="this is my page"></p><p> <!--<link rel="stylesheet" type="text/css" href="./styles.css" mce_href="styles.css">--></p><p> </head><br /> <mce:script type="text/javascript"><!--<br /> var http_request = false;<br /> function send_request(url) {//初始化、指定處理函數、發送請求的函數<br /> http_request = false;<br /> //開始初始化XMLHttpRequest對象<br /> if(window.XMLHttpRequest) { //Mozilla 瀏覽器<br /> http_request = new XMLHttpRequest();<br /> if (http_request.overrideMimeType) {//設定MiME類別<br /> http_request.overrideMimeType('text/xml');<br /> }<br /> }<br /> else if (window.ActiveXObject) { // IE瀏覽器<br /> try {<br /> http_request = new ActiveXObject("Msxml2.XMLHTTP");<br /> } catch (e) {<br /> try {<br /> http_request = new ActiveXObject("Microsoft.XMLHTTP");<br /> } catch (e) {}<br /> }<br /> }<br /> if (!http_request) { // 異常,建立對象執行個體失敗<br /> window.alert("不能建立XMLHttpRequest對象執行個體.");<br /> return false;<br /> }<br /> http_request.onreadystatechange = processRequest;<br /> // 確定發送請求的方式和URL以及是否同步執行下段代碼<br /> http_request.open("GET", url, true);<br /> http_request.send(null);<br /> }<br /> // 處理返回資訊的函數<br /> function processRequest() {<br /> if (http_request.readyState == 4) { // 判斷對象狀態<br /> if (http_request.status == 200) { // 資訊已經成功返回,開始處理資訊<br /> alert(http_request.responseText);<br /> } else { //頁面不正常<br /> alert("您所請求的頁面有異常。");<br /> }<br /> }<br /> }<br /> function userCheck() {<br /> var f = document.form1;<br /> var username = f.username.value;<br /> if(username=="") {<br /> window.alert("The user name can not be null!");<br /> f.username.focus();<br /> return false;<br /> }<br /> else {<br /> send_request('check1.jsp?username='+username);<br /> }<br /> }</p><p>// --></mce:script><br /> <body><br /> <form name="form1" action="" method="post"><br /> User Name:<input type="text" name="username" value=""> <br /> <input type="button" name="check" value="check" onClick="userCheck()"><br /> <input type="submit" name="submit" value="submit"><br /> </form><br /> </body><br /> </html><br />本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/sunrisefe/archive/2006/01/16/580474.aspx
check1.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %><br /> <%<br /> String username= request.getParameter("username");<br /> if("educhina".equals(username))<br /> {<br /> out.print("使用者名稱已經被註冊,請更換一個使用者名稱。");<br /> }<br /> else<br /> {<br /> out.print("使用者名稱尚未被使用,您可以繼續。");<br /> }<br /> %>