Javaweb The simplest use of Ajax in history to determine whether a user name is registered (do not jump to the page!) )

Source: Internet
Author: User

About the front end:

Use jquery-3.3.1.js Remember to import Austrian---Finally I will attach my source

Hey, I don't have to say a lot of beginners and rookie jquery really don't understand! Look at the code! I will write my understanding of this procedure in individual places.

About the backstage, the servlet.

There is no real link database in the background you know how to join your test, but also to build a table, very troublesome, roughly write a template, you link to the database, change the code of thought should be very simple!! What I say makes sense!! A few simple words to see the code!!

Index.jsp//by Wolf <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
servlet file 
Package Com.ajax;import Java.io.ioexception;import Java.util.arrays;import java.util.list;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 Valiateusername */@WebServlet (asyncsupported = true, Urlpatterns = {"/valiateusername"}) public CLA SS Valiateusername extends HttpServlet {/** * @see httpservlet#doget (httpservletrequest request, HttpServletResponse Response) */protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//TODO auto-generated method stub}/** * @see httpservlet#dopost (httpservletrequest request, HttpServletResponse response) */protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//TODO auto-generated Method Stubdoget (request, response); Response.setcharaCterencoding ("Utf-8"); Request.setcharacterencoding ("Utf-8"); String Username=request.getparameter ("username"); System.out.println ("User name" +username); list<string> usernames =arrays.aslist ("AAA", "BBB", "CCC");//equivalent to create an array here, the following words if the array contains these words, then the front-end prompt information user has been registered! String result=null;if (Usernames.contains (username)) {result= "<font color= ' Red ' > The user name has been used </font>"; SYSTEM.OUT.PRINTLN (result);} else {result= "<font color= ' Red ' > The user keyi use </font>"; SYSTEM.OUT.PRINTLN (result);} Response.setcontenttype ("text/html");//Here is the text format returned in HTML format response.getwriter (). Print (result),//Send the message back to the front-end JSP page}}

Run:

Source Code Link Invalid comment Supplement link:: Https://pan.baidu.com/s/1c3L06Ow

Javaweb The simplest use of Ajax in history to determine whether a user name is registered (do not jump to the page!) )

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.