• $.ajax邮箱验证


    package com;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    @WebServlet(name = "emailServlet",urlPatterns = "/emailServlet")
    public class emailServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            super.doGet(req, resp);
            this.doPost(req,resp);
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            resp.setCharacterEncoding("utf-8");
            String email = req.getParameter("email");
            System.out.println(email);
            boolean flag = false;
            if(email.equals("1391614208@qq.com")){
                resp.getWriter().print("true");
            }else{
                resp.getWriter().print("false");
            }
        }
    }
    emailServlet
    <%--
      Created by IntelliJ IDEA.
      User: SuSh1
      Date: 2019/10/17
      Time: 8:25
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <script src="js/jquery-1.12.4.min.js"></script>
        <%
            String contextPath = request.getContextPath();
            request.setAttribute("contextPath",contextPath);
        %>
        <script type="text/javascript">
            function getXMLhttp() {
                if (window.XMLHttpRequest){
                    return new XMLHttpRequest();
                } else if (window.ActiveXObject){
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            function kgc(){
                var email = $("#email").val();
                if(email == null || email == ""){
                    $("#emailId").html("邮箱不能为空");
                }else{
                    xmlhttp = getXMLhttp();
                    var url = "${contextPath}/emailServlet";
                    var info = "email="+email;
                    $(function () {
                        $.ajax({
                            "url":url,
                            "type":"POST",
                            "data":info,
                            "dataType":"text",
                            "success":ifsuccess ,
                            "error":function () {
                                alert("请联系系统管理员");
                            }
    
                        })
    
                    })
                    function ifsuccess(data) {
                        if(data=="true"){
                            //$("#emailId").html("邮箱不可用");
                            document.getElementById("emailId").innerText = "邮箱不可用";
                            //$("#emailId").html("邮箱不可用");
    
                        }else{
                            $("#emailId").html("邮箱可用");
    
                        }
    
                    }
                }
            }
        </script>
        <title>验证email</title>
    </head>
    <body>
    <form action="" method="post">
        邮箱:<input type="email" name="email" id="email" placeholder="请输入有效邮箱:" onblur=" kgc();">
        <input type="submit" value="提交">
        <div id="emailId" style="display: inline"></div>
    </form>
    
    </body>
    </html>
    email.jsp

  • 相关阅读:
    C#调用Delphi的dll 详解
    C# 用API截取桌面屏幕
    C# 控件代码设置置顶和置底属性
    C#用API 获取电脑桌面背景图地址
    利用JS使IE浏览器默认打开是全屏显示
    aspx页面生成xml数据
    MacOS下安装Anaconda+Pycharm+TensorFlow+Keras
    GitHub编辑README
    Win10(64位)下安装Anaconda+Tensorflow(GPU)
    Win7(64位)下安装Anaconda+Tensorflow(CPU)
  • 原文地址:https://www.cnblogs.com/lev1/p/11692639.html
Copyright © 2020-2023  润新知