对重复值的效验
新增页面
//用户编号已存在校验
function validayhbh(){
var yhbhv=document.getElementById('YHBH').value;
var swid=document.getElementById('wid').value;
var yhbhsfcz = "";
$.ajax({
type: "POST",
url: "<%=request.getContextPath() %>/ggdmzdgl/yh/yh_yhbhvalida.jsp",
cache: false,
async:false,
data: {yhbh:yhbhv,wid:swid},
dataType:'text',
success:function(result){
yhbhsfcz = result;
}
});
if(yhbhsfcz!="-1"){
document.getElementById('YHBH').focus();
document.getElementById('YHBH').value="";
alert("您输入的用户编号已经注册,请重新输入!");
return false;
}
return true;
}
yh_yhbhvalida.jsp
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="org.apache.commons.lang.StringUtils"%> <%@ page import="java.util.Map"%> <%@ page import="sun.jdbc.rowset.CachedRowSet"%> <%@ page import="com.ekingstar.zcgl.bean.sqlDirect"%> <%@ page import="com.ekingstar.zcgl.bean.SystemParameterBeans"%> <%@ page import="java.util.List"%> <%@ page import="java.util.ArrayList"%> <%@ page import="net.sf.json.JSONArray"%> <%@ page import="java.util.HashMap"%> <% try{ response.setContentType("text/html;charset=utf-8"); String yhbh = StringUtils.defaultIfEmpty(request.getParameter("yhbh"),"").trim(); String wid = StringUtils.defaultIfEmpty(request.getParameter("wid"),"").trim(); sqlDirect sd = new sqlDirect(); String returnVal="-1"; String sql = ""; if("".equals(wid)||"null".equals(wid)){ sql = "select wid from zc_yh where yhbh = '"+yhbh+"' "; }else{ sql = "select wid from zc_yh where yhbh = '"+yhbh+"' and wid <>'"+wid+"'"; } //System.out.println(sql); CachedRowSet crs = sd.exeQuery(sql); if(crs.next()){ returnVal="1"; } response.getWriter().write(returnVal); response.getWriter().flush(); response.getWriter().close(); }catch(Exception e){ e.printStackTrace(); } %>
原文链接:https://www.f2er.com/ajax/161272.html