虽然是小小的成功心理也很开心~~!
保存代码:
这里是与数据库交互:
login.jsp
<%
String name=request.getParameter("name"); String pwd=request.getParameter("pwd"); UserBean ub=new UserBean(); if(ub.isExist(name)){ //用户是否存在 if( ub.valid(name, pwd)){ //密码是否正确 out.print("欢迎登陆:"+name); }else{ out.print("密码错误!"); } }else{ out.print("用户不存在:"); }%>
ajax 请求页面 :
<html>
<head><script type="text/javascript">function loadXMLDoc(){ var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }var name=document.getElementById("name").value;var pwd=document.getElementById("pwd").value;xmlhttp.open("post","login.jsp?name="+name+"&pwd="+pwd,true);xmlhttp.send();}</script></head><body><h2>AJAX</h2>
<input type="text" name="name" id="name"><input type="text" name="pwd" id="pwd"><button type="button" οnclick="loadXMLDoc()">请求数据</button><div id="myDiv"></div></body>
</html>本来很简单却花了一天的时间。。360浏览器好坑爹啊 ~!