encodeURIComponent传入后台解码

来源:互联网 发布:数据整合系统sci 编辑:程序博客网 时间:2024/05/30 22:45
<script>$(document).ready(function() {$("#name").focus();$("#inputForm").validate({   rules:{     code:{      required:true,      rangelength:[5,10],      remote:"${ctx}/sierac/product/check?oldcode=" + encodeURIComponent('${product.code}') //此处传入后台     },     name:{       required:true,      rangelength:[1,10]     },     shelfLife:{     required:true,     digits:true     },     pcsPerCtn:{      required:true,     digits:true     }   },   messages:{    code:{      required:"产品编码不能为空",      rangelength:"编码长度在5-10之间",      remote:"该产品编码已经存在,请重新输入"    },       name:{       required:"产品名称不能为空",       rangelength:"产品名称长度介于1-10之间"    },    shelfLife:{     required:"保质期不能为空",     digits:"必须为整数"    },    pcsPerCtn:{    required:"每箱单品数不能为空",     digits:"单品数必须为整数"    }   },submitHandler: function(form){loading('正在提交,请稍等...');form.submit();},errorContainer: "#messageBox",errorPlacement: function(error, element) {$("#messageBox").text("输入有误,请先更正。");if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){error.appendTo(element.parent().parent());} else {error.insertAfter(element);}}});});</script>
<form:form id="inputForm" modelAttribute="product" action="${ctx}/sierac/product/save" method="post" class="form-horizontal"><form:hidden path="id"/><sys:message content="${message}"/><div class="control-group"><label class="control-label" id="code">产品代码:</label><div class="controls"> <c:choose>                                        <c:when test="${empty product.id}">                                                <form:input path="code" htmlEscape="false" maxlength="255"                                                        class="input-xlarge" />                                        </c:when>                                        <c:otherwise>                                                <form:input path="code" htmlEscape="false" maxlength="255"                                                        class="input-xlarge" readonly="true" />                                        </c:otherwise>                                </c:choose><span class="help-inline"><font color="red">*</font> </span></div></div>

后台:

 @ResponseBody    @RequiresPermissions("sierac:product:edit")    @RequestMapping(value = "check")    public String check(HttpServletRequest request ,String oldcode, String code) throws UnsupportedEncodingException {        String s = new String(request.getParameter("code").getBytes("ISO8859-1"), "UTF-8");//encodeURIComponent编码转换        if (s !=null && s.equals(oldcode)) {return "true";//不重复} else if (s !=null && productService.findByCode(s)==null) {return "true"; //不重复}return "false"; //重复}



0 0