Using AJAX to implement user name detection (JavaScript method)

Source: Internet
Author: User

1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<script type= "Text/javascript" >Ten var req; One function Check () A { -var url = "Checkuser?uname=" + document.getElementById ("uname"). Value; -     if(window. XMLHttpRequest) the     { -req =NewXMLHttpRequest (); -     } -     Else if(window. ActiveXObject) { +req =NewActiveXObject ("Microsoft.XMLHTTP"); -     }        +Req.open ("GET", URL,true); AReq.onreadystatechange =Show; atReq.send (NULL); -Alert ("HHHH"); - } - function Show () { -     if(Req.readystate = = 4) { -         if(Req.status = = 200) { indocument.getElementById ("Info"). innerhtml=Req.responsetext; -         } to     } + } -</script> the<body> *<table> $<tr><td> username </td><td><input type= "text" id= "uname" ></td></tr>Panax Notoginseng<tr><td><input type= "button" onclick= "Check ()" value= "Detect user" ></td><td><div id= " Info "></div> </td></tr> -</table> the</body> +
1  PackageJavastudy;2 3 Importjava.io.IOException;4 Importjavax.servlet.ServletException;5 ImportJavax.servlet.annotation.WebServlet;6 ImportJavax.servlet.http.HttpServlet;7 Importjavax.servlet.http.HttpServletRequest;8 ImportJavax.servlet.http.HttpServletResponse;9 Ten /** One * Servlet Implementation class CheckUser A  */ -@WebServlet ("/checkuser") -  Public classCheckUserextendsHttpServlet { the     Private Static Final LongSerialversionuid = 1L; -         -     /** -      * @seeHttpservlet#httpservlet () +      */ -      PublicCheckUser () { +         Super(); A         //TODO auto-generated Constructor stub at     } -  -     /** -      * @seeHttpservlet#doget (httpservletrequest request, httpservletresponse response) -      */ -     protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException { in         //TODO auto-generated Method Stub -String uname=request.getparameter ("uname"); toString[] names={"Zhang", "Yang", "Wang"}; +         Booleanflag=true; -          for(intI =0;i<names.length;i++) the         { *             if(Names[i].equals (uname)) $             {Panax Notoginsengflag=false; -                  Break; the             } +              A         } theResponse.setcharacterencoding ("Utf-8"); +         if(flag==false) -         { $Response.getwriter (). println ("The user name is registered!!!"); $         } -         Else -         { theResponse.getwriter (). println ("Registered success!!! "); -         }Wuyi //response.getwriter (). Append ("Served at:"). Append (Request.getcontextpath ()); the     } -  Wu     /** -      * @seeHttpservlet#dopost (httpservletrequest request, httpservletresponse response) About      */ $     protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException { -         //TODO auto-generated Method Stub - doget (request, response); -     } A  +}

Using AJAX to implement user name detection (JavaScript method)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.