jquery Asynchronous Function instances

Source: Internet
Author: User
Tags string format

jquery is really a good JavaScript framework, and today we use our spare time to give you an example of the uniqueness of using jquery asynchronous implementation to verify the user name:

Code 1--index.jsp File:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%string basepath = request.getscheme () +"://"+request.getservername () +" : "+request.getserverport () +request.getcontextpath () +"/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

Code 2--jqueryajaxcheckusernameservlet.java File:

Package Com.ghj.packagofserlet;import Java.io.ioexception;import Java.io.printwriter;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public Class Jqueryajaxcheckusernameservlet extends HttpServlet {private static final long serialversionuid = 6387744976765210524L; public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { DoPost (request,response);} public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {try{ Response.setcharacterencoding ("UTF-8"); Request.setcharacterencoding ("UTF-8"); System.out.println (1/0);//intentional exception to check index.jsp if the error method is available printwriter out = Response.getwriter (); String username=request.getparameter ("UserName");//Gets the "user name" if ("admin". Equals (UserName)) {out.write ("{\" flag\ ": \" False\ "}");//"false" indicates that the user name is not available. } else {out.write ("{\" flag\ ": \" True\ "}");//"TruE "indicates that the user name is available. }out.flush (); Out.close ();} catch (Exception e) {e.printstacktrace (); Response.setstatus (405);//The error method in index.jsp is executed at this time. }}}

Code 3--web.xml File:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "/http Www.w3.org/2001/XMLSchema-instance "xmlns=" Http://java.sun.com/xml/ns/javaee "xmlns:web=" Http://java.sun.com/xml /ns/javaee/web-app_2_5.xsd "xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/ Javaee/web-app_2_5.xsd "id=" webapp_id "version=" 2.5 "> <servlet> <servlet-name> Jqueryajaxcheckusernameservlet</servlet-name> <servlet-class> Com.ghj.packagofserlet.jqueryajaxcheckusernameservlet</servlet-class> </servlet> <servlet-mapping > <servlet-name>JqueryAjaxCheckUserNameServlet</servlet-name> <url-pattern>/ Jqueryajaxcheckusernameservlet</url-pattern> </servlet-mapping> <welcome-file-list> < Welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app> 
Note: The above example uses the Jquery-1.8.3.min.js file, which can be found in the download resources below.

"0-minute download resources "

" Asynchronous submission of jquery forms using Loadmask "

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.