jquery-validation + springmvc 表单验证

    JSP 页面

    <script src="${pluginpath}/jquery1.11.3/jquery-1.11.3.min.js" type="text/javascript"></script>
    <!-- validation -->
    <script src="${pluginpath}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="${pluginpath}/jquery-validation/additional-methods.js" type="text/javascript"></script>
    <script src="${pluginpath}/jquery-validation/localization/messages_zh.min.js" type="text/javascript"></script>
    <link href="${pluginpath}/jquery-validation/jquery.validate.min.css"  rel="stylesheet" type="text/css"></link>


    <form action="${syspath}/login" method="post" target="_top" id="loginform">
    <input type="text" class="form-control" id="username" name="username">
    <input type="password" class="form-control" id="password" name="password" required="true">
    <input type="password" class="form-control" id="password1" name="password1" required="true"       equalTo="#password">
  <button type="submit">登录</button>
 </form>   


    <script type="text/javascript">
        $("#loginform").validate({
            rules:{
                    username:{
                        required:true,
                        async : false,
                        remote: '${syspath}/loginIdCheck'
                    }
           },
              messages: {
                    username: {
                        remote : "该用户名已存在"
                    },
                    password1: {
                        equalTo : '确认密码必须与密码相同'
                    }
                }
        });
    </script>


     后台springmvc controller

     //用户

     @RequestMapping("/loginIdCheck")
     public void getUserIdCheck(HttpServletRequest request, HttpServletResponse reponse) {
        //HttpUtil.getRequestToMap(request);

       String username = request.getParameter("username");

        try {

             //判断用户名是否唯一

            //只能输出 true false

            //reponse.getWriter().write(Boolean.FALSE+"");
            reponse.getWriter().write(Boolean.TRUE+"");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

转载于:https://my.oschina.net/weaponking/blog/647363

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值