栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

JQuery用户名校验的具体实现

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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



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;


public class UserVerify extends HttpServlet {
  
  
  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();
    }
  } 

  // 
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  } 

  
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  }

  
  public String getServletInfo() {
    return "Short description";
  }// 

}

以上就是本文的全部内容,希望对大家的学习有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/97892.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号