Learning JavaScript Asynchronous checksums is often learned from the most traditional xmlhttprequest, and this article discusses the understanding of traditional checksums:
Code 1index.jsp files:
<%@ 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 2demo1.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 3demo2.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 4ajaxcheckusernameservlet.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 Ajaxcheckusernameservlet extends HttpServlet {private static final long Serialversionuid = 638774497676
5210524L; /** * Processing demo1.jsp Asynchronous Validation * * @author Gaohuanjie/public void doget (HttpServletRequest request, Httpserv
Letresponse response) throws Servletexception, IOException {try{response.setcharacterencoding ("UTF-8");
Request.setcharacterencoding ("UTF-8");
PrintWriter out = Response.getwriter (); System.out.println (1/0);//intentionally unexpected exception to check whether the branch statement xmlhttprequest.status!=200 in Demo1.jsp is available with String username=
Request.getparameter ("UserName")//Get "username" System.out.println ("Processing demo1.jsp asynchronous authentication, Username:" +username); if ("admin". Equals (UserName)) {
Out.print ("1");//"1" indicates that the user name is not available.
else {out.print ("2");//"2" indicates that the user name is available.
} out.flush ();
Out.close ();
}catch (Exception e) {e.printstacktrace ();
Response.setstatus (405); demo2.jsp Asynchronous Validation * * @author Gaohuanjie/public void DoPost (HttpServletRequest re)/** * processing Quest, HttpServletResponse response) throws Servletexception, IOException {try{response.setcharacterencoding (
"UTF-8");
Request.setcharacterencoding ("UTF-8");
PrintWriter out = Response.getwriter (); System.out.println (1/0);//intentionally unexpected exception to check whether the branch statement xmlhttprequest.status!=200 in Demo2.jsp is available with String username=
Request.getparameter ("UserName")//Get "username" System.out.println ("Processing demo2.jsp asynchronous authentication, Username:" +username);
if ("admin". Equals (UserName)) {Out.print ("1");//"1" indicates that the user name is not available.
else {out.print ("2");//"2" indicates that the user name is available.
} out.flush ();
Out.close (); }catch (excePtion e) {e.printstacktrace ();
Response.setstatus (405);
}
}
}
Code 5web.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>ajaxcheckusernameservlet </servlet-name>
<servlet-class>com.ghj.packagofserlet.ajaxcheckusernameservlet</ servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Ajaxcheckusernameservlet</servlet-name>
<url-pattern>/ajaxcheckusernameservlet</ url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file> Index.jsp</welcome-file>
</welcome-file-list>
The above is the use of traditional methods to implement the detailed code of asynchronous checksum, I hope to help you learn.