Check whether the username is unique (instance Code) and the AJAX application instance is used for ajax application instances.

Source: Internet
Author: User

Check whether the username is unique (instance Code) and the AJAX application instance is used for ajax application instances.

The following code is displayed:

The following is a simple example to check whether the user name is unique (directly refer to the Code ):

Front-End Interface:

<% @ Page language = "java" contentType = "text/html; charset = GB18030" pageEncoding = "GB18030" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN "" http://www.w3.org/TR/html4/loose.dtd "> <Html> 

AJAX file:

<Script language = "javascript"> function createRequest (url) {http_request = false; if (window. XMLHttpRequest) {// non-IE browser http_request = new XMLHttpRequest (); // create XMLHttpRequest object} else if (window. activeXObject) {// IE browser try {http_request = new ActiveXObject ("Msxml2.XMLHTTP"); // create an XMLHttpRequest object} catch (e) {try {http_request = new ActiveXObject ("Microsoft. XMLHTTP "); // create an XMLHttpRequest object} c Atch (e) {}} if (! Http_request) {alert ("You cannot create an XMLHttpRequest object instance! "); Return false;} http_request.onreadystatechange = getResult; // call the return result processing function http_request.open ('get', url, true ); // create a connection with the server: http_request.send (null); // send a request to the server} function getResult () {if (http_request.readyState = 4) {// determine the Request status if (http_request.status = 200) {// if the request is successful, process the returned result document. getElementById ("toolTip "). innerHTML = http_request.responseText; // you can specify the document content. getElementById ("toolTip "). st Yle. display = "block"; // display prompt box} else {// The request page has an error alert ("the page you requested has an error! ") ;}} Function checkUser (userName) {if (userName. value =" ") {alert (" Enter your userName! "); UserName. focus (); return;} else {createRequest ('checkuser. jsp? User = '+ userName. value) ;}</script>

Jsp file:

In this example, the database is not connected, but the registered user is simply represented by an array.

<% @ Page language = "java" import = "java. util. * "pageEncoding =" GB18030 "%> <% String [] userList = {" Tomorrow technology "," mr "," mrsoft "," wgh "}; // create a one-dimensional array String user = new String (request. getParameter ("user "). getBytes ("ISO-8859-1"), "GB18030"); // get the username Arrays. sort (userList); // sorts the array int result = Arrays. binarySearch (userList, user); // search for an array if (result>-1) {out. println ("sorry, this user name has been registered! "); // Output detection result} else {out. println (" congratulations, this user name is not registered! "); // Output detection result }%>

Summary

The above section describes how to check whether the user name of an AJAX application instance is unique (the instance Code). I hope it will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.