JQuery用户名校验的具体实现
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要为大家详细介绍了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 .linying; import java.io.IOException; import java.io.PrintWriter; import java..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> }
以上就是本文的全部内容,希望对大家的学习有所帮助。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指