Home > Web Front-end > JS Tutorial > Specific implementation of JQuery user name verification_jquery

Specific implementation of JQuery user name verification_jquery

WBOY
Release: 2016-05-16 15:10:10
Original
1419 people have browsed it

This example shares the JQuery username verification function for everyone for your reference. The specific content is as follows

$(document).ready(function(){}): Define the method that needs to be executed when the page is loaded.
$() gets the node specified by the page, and the parameter is some kind of CSS selector. What is returned is a JQuery object on which JQuery methods can be executed.
The val() method can obtain the value attribute value of the node
html() sets the html content in a node
click() corresponding mouse click event
keyup() corresponding keyboard pop-up event
$.get() can interact with the server in get mode. The registered callback method will be called when the data comes back. This method will receive a plain text parameter that represents the data returned by the server
addClass()removeClass() Add or delete a class to a node
Solve the problem of Chinese garbled characters: The data sent to the server is encoded twice in js, and then URLDecoded once in UTF-8 in the server code

Main code:

$.get("http://localhost:8080/JQueryStudy/UserVerify?userName=" + encodeURI(encodeURI(userName)),null,
          function(response){
            $("#result").html(response);
          }
        )
Copy after login

Processed Servlet

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.linying;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户名验证Servlet
 * @author Ying-er
 * @time 2010-4-25下午08:02:08
 * @version 1.0
 */
public class UserVerify extends HttpServlet {
  
  /** 
  * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  * @param request servlet request
  * @param response servlet response
  */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      String param = request.getParameter("userName");
      if (param == null || param.length() == 0) {
        out.println("用户名不能为空");
      } else {
        String userName = URLDecoder.decode(param, "UTF-8");
        System.out.println(userName);
        if (userName.equals("Ying-er")) {
          out.println("用户名[" + userName + "]已经存在,请使用别的用户名注册");
        } else {
          out.println("可以使用用户名[" + userName + "]注册");
        }
      }
    } finally { 
      out.close();
    }
  } 

  // <editor-fold defaultstate="collapsed" desc="HttpServlet">
  /** 
  * Handles the HTTP <code>GET</code> method.
  * @param request servlet request
  * @param response servlet response
  */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  } 

  /** 
  * Handles the HTTP <code>POST</code> method.
  * @param request servlet request
  * @param response servlet response
  */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  }

  /** 
  * Returns a short description of the servlet.
  */
  public String getServletInfo() {
    return "Short description";
  }// </editor-fold>

}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone’s study.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template