ajax 表单验证 JSP
前台代码:
<script type="text/javascript"> function checkInDB() { with (loginForm) { 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) { var s=xmlhttp.responseText; alert(s); } } xmlhttp.open("POST", "UserLogin", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("userType="+userType.value+"&userID=" + userID.value + "&userPassword=" + userPassword.value); } }</script>
response.setContentType("text/html; charset=gb2312");response.setHeader("Cache-Control", "no-cache");PrintWriter out=response.getWriter();out.write("UserNotFound!");out.close();
if(userType.equals("reader")){ readerLoginIn(request,response); return ; } if(userType.equals("manager")){ managerLoginIn(request,response); return ; }