The web page uses the traditional method to Implement Asynchronous verification details, asynchronous Verification

Source: Internet
Author: User

The web page uses the traditional method to Implement Asynchronous verification details, asynchronous Verification

JavaScript asynchronous verification is often learned from the most traditional XMLHttpRequest. On Saturday, let's talk about the traditional verification:

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 -- demo1.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 3 -- demo2.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 4 -- AjaxCheckUserNameServlet. 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 = 6387744976765210524L;/*** process asynchronous verification in demo1.jsp * * @ Author GaoHuanjie */public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {response. setCharacterEncoding ("UTF-8"); request. setCharacterEncoding ("UTF-8"); PrintWriter out = response. getWriter (); // System. out. println (1/0); // check xmlHttpRequest in demo1.jsp if an exception occurs intentionally. status! String userName = request. getParameter ("userName"); // obtain the "user name" System. out. println ("Asynchronous Authentication in demo1.jsp processing, userName:" + userName); if ("admin ". equals (userName) {out. print ("1"); // "1" indicates that the user name is unavailable.} Else {out. print ("2"); // "2" indicates that the user name is available .} Out. flush (); out. close ();} catch (Exception e) {e. printStackTrace (); response. setStatus (405) ;}/ *** process asynchronous verification in demo2.jsp ** @ author GaoHuanjie */public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {response. setCharacterEncoding ("UTF-8"); request. setCharacterEncoding ("UTF-8"); PrintWriter out = response. getWriter (); // System. out. println (1/0 );/ /Deliberately exception occurs to check xmlHttpRequest. status in demo2.jsp! String userName = request. getParameter ("userName"); // obtain the "user name" System. out. println ("process asynchronous verification in demo2.jsp, userName:" + userName); if ("admin ". equals (userName) {out. print ("1"); // "1" indicates that the user name is unavailable .} 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 5 -- 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>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></web-app>
Download resources at 0 Points]


Asynchronous Communication Verification questions.

(1) Use the parity bit detection method;
(2) Yes. The parity bit shows that the number of 1 Codes sent from machine B is an even number, but the actual number is an odd number. Therefore, an error is detected;
(3) No. The parity bit is an error detection code. If the parity bit determines that no error occurs, it cannot determine which one has an error.

New users Learn How to Implement Asynchronous input verification (simple) in java web implementation without connecting to the database and directly determining that the admin user is occupied

I suggest
If a newbie does exercises
Do it yourself.
The results will be different.
------------------------
The program you mentioned
10 people will look like 10
You cannot determine which one is better.
-------------------------
Common ajax for asynchronous Verification
There are many examples of Baidu ajax.
The main process is to submit ajax to the backend for processing the callback method to receive and return
Json and other data formats can be extended.

Suggestions

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.