中文字幕免费精品_亚洲视频自拍_亚洲综合国产激情另类一区_色综合咪咪久久

JQuery用戶名校驗的具體實現
來源:易賢網 閱讀:950 次 日期:2016-07-19 14:51:44
溫馨提示:易賢網小編為您整理了“JQuery用戶名校驗的具體實現”,方便廣大網友查閱!

本實例為大家分享了JQuery用戶名校驗功能,分享給大家供大家參考,具體內容如下

$(document).ready(function(){}):定義頁面裝載完成時,需要執行的方法。

$()獲得頁面指定的節點,參數是某種CSS的選擇器。返回的是一個JQuery對象,可在其上執行JQuery方法。

val()方法可以獲得節點的value屬性值

html()設定某個節點中的html內容

click()相應鼠標點擊事件

keyup()相應鍵盤彈起事件

$.get()可以和服務器進行get方式的交互,注冊的callback方法會在數據回來的時候被調用,此方法會接收到代表服務器端返回數據的一個純文本的參數

addClass()removeClass()給某個節點增加或刪除一個class

解決中文亂碼問題:發送給服務器端的數據在js中做兩次encodeURI,然后在服務器端的代碼中按UTF-8的方式做一次URLDecode

主要代碼:

$.get("http://localhost:8080/JQueryStudy/UserVerify?userName=" + encodeURI(encodeURI(userName)),null,

          function(response){

            $("#result").html(response);

          }

        )

處理的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>

}

以上就是本文的全部內容,希望對大家的學習有所幫助。

更多信息請查看網絡編程
易賢網手機網站地址:JQuery用戶名校驗的具體實現
由于各方面情況的不斷調整與變化,易賢網提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢為準!

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
云南網警備案專用圖標
聯系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
云南網警報警專用圖標
主站蜘蛛池模板: 五河县| 南和县| 浏阳市| 宁陵县| 葵青区| 济南市| 博乐市| 常州市| 林西县| 喀喇沁旗| 巴青县| 监利县| 罗山县| 盘锦市| 钟祥市| 汝阳县| 醴陵市| 临高县| 沈阳市| 汶上县| 建水县| 蒙山县| 肃宁县| 英山县| 屏东县| 普兰店市| 什邡市| 大兴区| 饶河县| 彭水| 闽清县| 郴州市| 平远县| 尼玛县| 乌拉特后旗| 南康市| 昔阳县| 大姚县| 杂多县| 无棣县| 洛宁县|