日期:2014-05-20 浏览次数:20889 次
<script language="javascript"> var http_request = false; function createRequest(url) { //初始化对象并发出XMLHttpRequest请求 http_request = false; if (window.XMLHttpRequest) { // Mozilla或其他除IE以外的浏览器 http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType("text/xml"); } } else if (window.ActiveXObject) { // IE浏览器 try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert("不能创建XMLHTTP实例!"); return false; } http_request.onreadystatechange = alertContents; //指定响应方法 //发出HTTP请求 http_request.open("GET", url, true); http_request.send(null); } function alertContents() { //处理服务器返回的信息 if (http_request.readyState == 4) { if (http_request.status == 200||http_request.status==0) { alert(http_request.responseText); } else { alert('您请求的页面发生错误!'); } } } function checkName() { var username = form1.username.value; if(username=="") { window.alert("请添写用户名!"); form1.username.focus(); return false; } else { createRequest('checkName.jsp?username='+username); } } </script>
<td width="293" id="td1"><input type="text" id="username" name="username"/> <input type="button" value="检测用户名" onClick="checkName()"></td>
<%//request.setCharacterEncoding("GB2312"); String username=request.getParameter("username"); try{ Class.forName("com.mysql.jdbc.Driver"); }catch (ClassNotFoundException e) { e.printStackTrace(); } // try{ Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/hrm","root","root"); /* }catch (SQLException e) { e.printStackTrace(); }*/ Statement stmt=conn.createStatement(); String sql="select * from userinfo where userName='"+username+"'"; ResultSet rs=stmt.executeQuery(sql); if (rs.next()){ out.println("很报歉!用户名"+username+"已经被注册!"); }else{ out.println("祝贺您!用户名"+username+"没有被注册!"); } rs.close(); conn.close(); stmt.close();%>