checking for the uniqueness of a value using jquery validation

I am trying to check whether the input value already exists in the database and let the user know about it using this Jquery validator.

it has a example for checking the uniqueness of a input value here.

In my case I use Java with Spring MVC .

This is how I do it.

In my jsp page

var agrmntNo = jQuery('#agreementNo').val();

    $("#myform").validate(
    {
        rules: 
        {
             agreementNo: 
            {
                required: true,
               remote:'/TFProject/check_agreementNo'+agrmntNo+'.htm'
            }
        },
        messages: 
        {
            agreementNo: 
            {
                required: "Please enter.",
                remote:"This agreement number has already been used !."
            }
        }
    });

This is the Java method I use.

@RequestMapping(value="/check_agreementNo1{agrmntNo}.htm", method = RequestMethod.GET)
        public boolean check_agreementNo (@PathVariable("agrmntNo") String agrmntNo){


            System.out.println("DEBUG:Inside check agreement No in PMS Controller");
            System.out.println("DEBUG: URL parameter is : "+agrmntNo);

            AgreementBean agrbn = new AgreementBean();

            agrbn.setAgrmntNo(agrmntNo);

            String rslt = customerservice.check_agreementNo(agrbn);

            if(Integer.parseInt(rslt) > 0){
                return true;
            }else{
                return false;
            }

        }

In this case, it gets into the Java method. But the parameter is not get passed. Once I submit my form, I can see this in my browser console.

GET http://localhost:8081/TFProject/check_agreementNo1.htm?agreementNo=54 500 (Internal Server Error)

it seems it does not recognize the way(the way in spring ) parameter is passed. What Can I do?

Thank you!


The validation library clearly passes the value as a query parameter. You can't add a value to the remote parameter like you're doing.

The most sensible thing to do is to change your Java method to accept a request parameter instead of a path variable. Your scheme is bad and confusing anyway, because "/check_agreementNo1{agrmntNo}.htm" doesn't correspond to REST or any other sensible standard.

链接地址: http://www.djcxy.com/p/61098.html

上一篇: 如何在Spring Boot中创建自定义验证器注释?

下一篇: 使用jquery验证检查值的唯一性