Ajax uses the original ecology JS to verify that the username exists _javascript skill

Source: Internet
Author: User

Directly on the code:
Reg_ajax.html

<! DOCTYPE html>  

The

requested servlet code is as follows, Userservlet.java

Package cn.bestchance.servlet;
Import java.io.IOException;

Import java.util.ArrayList;
Import javax.servlet.ServletException;
Import Javax.servlet.annotation.WebServlet;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;

Import Javax.servlet.http.HttpServletResponse; /** * Servlet Implementation class Userservlet/@WebServlet ("/userservlet") public class Userservlet extends HTTPSERVL


  Et {private static final long serialversionuid = 1L;
    protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
  DoPost (request, response); /** * @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response) * * protected void DoP OST (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {String username=r
    Equest.getparameter ("username"); This uses ArrayList instead of querying data from the database arraylist<string> userlist =new ARRAYLIST&LT
    String> ();
    Userlist.add ("admin");
    Userlist.add ("test");
    Userlist.add ("chance");
    Verify that the username exists Boolean flag = false;
        for (String string:userlist) {if (String.Equals (username)) {flag = true;
      Break
    } if (flag) {//user name already exists response.getwriter (). Print ("yes");
    }else{//user name does not exist Response.getwriter (). Print ("no");


 }
  }

}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.