Home > Back-end >  Ajax check registration page user repeat
Ajax check registration page user repeat

Time:09-18

Using the post method, and finally a life data error, before you write is good, you can run, but now you have the wrong don't know why

Page code
 
<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;



<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
Registration page & lt;/title> <br/><link rel="stylesheet" type="text/CSS" href="https://bbs.csdn.net/topics/css/regist.css" & gt; <br/><The script type="text/javascript" SRC="https://bbs.csdn.net/topics/js/jquery.min.js" & gt; </script> <br/><style type="text/CSS" & gt; <br/>The red {<br/>Color: OrangeRed; <br/>} <br/><br/>Green {<br/>Color: SpringGreen; <br/>} <br/></style> <br/></head> <br/><body> <br/><br/><Div & gt; <br/><Article> <br/><h1> Registration & lt;/h1> <br/><Div & gt; <br/><Form> <br/><br/><Div & gt; <br/><Input type="text" name="userName" id="name" placeholder="user name" & gt; <br/><Span id="span01" & gt; </span> <br/></div> <br/><Div & gt; <br/><Input type="password" name="PWD" placeholder="password" & gt; <br/></div> <br/><Div & gt; <br/><Input type="password" name="PWD" placeholder="confirm password" & gt; <br/></div> <br/><Div & gt; <br/><Input type="tel" name="userName" placeholder="phone number" & gt; <br/></div> <br/><Button> Registration & lt;/button> <br/></form> <br/><br/></div> <br/></article> <br/><Footer> <br/><Ul> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; Contact us & lt;/a> </li> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; About us & lt;/a> </li> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; Recruitment & lt;/a> </li> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; Links & lt;/a> </li> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; The company address & lt;/a> </li> <br/><Li> <A href="https://bbs.csdn.net/topics/#" & gt; Focusing on our & lt;/a> </li> <br/></ul> <br/></footer> <br/></div> <br/><br/><The table border="1" width="500" & gt; <br/><br/><br/><br/><tr> <br/><td> The user name & lt;/td> <br/><td> <Input type="text" name="" id=" name "placeholder=" please enter the user name "/& gt; <br/><Span id="span01" & gt; </span> </td> <br/></tr> <br/><tr> <br/><td> Password & lt;/td> <br/><td> <Input type="text" name="password" placeholder="please enter the password" & gt; </td> <br/></tr> <br/><tr> <br/><td> Confirm password & lt;/td> <br/><td> <Input type="text" name="password" placeholder="confirm password" & gt; </td> <br/></tr> <br/><tr> <br/><td> Email & lt;/td> <br/><td> <Input type="text" name="" & gt; </td> <br/></tr> <br/><tr> <br/><td> Introduction & lt;/td> <br/><td> <Input type="text" name="" & gt; </td> <br/></tr> <br/><tr> <br/><Td colspan="2" & gt; <Input type="submit" value="https://bbs.csdn.net/topics/" & gt; </td> <br/></tr> <br/><br/><br/></table> <br/><br/>JQ part of <br/><The script type="text/javascript" & gt; <br/>The function ajaxFunction () {<br/>Var xmlHttp; <br/>Try {//Firefox, Opera 8.0 +, Safari <br/>XmlHttp=new XMLHttpRequest (); <br/>} the catch (e) {<br/>Try {//Internet Explorer <br/>XmlHttp=new ActiveXObject (" Msxml2. XmlHttp "); <br/>} the catch (e) {<br/>Try {<br/>XmlHttp=new ActiveXObject (" Microsoft. XmlHttp "); <br/>} the catch (e) {<br/>} <br/>} <br/>} <br/><br/>Return the xmlHttp; <br/>} <br/><br/>Var na=document. GetElementById (" name "); <br/><br/>Na. Onblur=function () {<br/><br/>Var name=na. The value; <br/>Var request=ajaxFunction (); <br/><br/>Request. The open (" POST ", "/ajax/CheckUsernameServlet", true); <br/>Request. The onreadystatechange=function () {<br/>If (request. ReadyState==4 & amp; & Request. The status==200) {<br/>Var data=https://bbs.csdn.net/topics/request.responseText; <br/>Var span=document. GetElementById (" span01 "); <br/><br/>If (1) data=https://bbs.csdn.net/topics/={<br/>Span. InnerHTML="user name already exists!" ; <br/>Span. The className="red"; <br/>} else {<br/>Span. InnerHTML="username available!" ; <br/>Span. The className="green"; <br/>} <br/>} <br/>} <br/>Request. SetRequestHeader (" the content-type ", "application/x - WWW - form - urlencoded"); <br/>Request. Send (" name="+ name); <br/>} <br/></script> <br/></body> <br/></html> <br/></pre> <br/><br/>CheckUsernameServlet code <br/><pre> <br/>Package com. Ajax. Servlet. <br/><br/>import java.io.IOException; <br/>import java.sql.SQLException; <br/><br/>import javax.servlet.ServletException; <br/>import javax.servlet.annotation.WebServlet; <br/>import javax.servlet.http.HttpServlet; <br/>import javax.servlet.http.HttpServletRequest; <br/>import javax.servlet.http.HttpServletResponse; <br/><br/>The import com. Ajax. Dao. UserDao; <br/>The import com. Ajax. Dao. Impl. UserDaoImpl; <br/><br/><br/>@ WebServlet ("/CheckUsernameServlet ") <br/>nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Backend/9989.html" target="_blank" style="color:#999">https//www.codepudding.com/Backend/9989.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Backend/9988.html'>Java classes and inheritance for answers</a></div> <div class="detail-arr-right">Next:<a href='/Backend/9990.html'>The idea of community edition with jetty start hot deployment when how to do the debug</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Java+related' target='_blank'>Java related</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>