//ajax检查身份证是否重复------------------------------------------------------------------------------------------------ var http = getHTTPObject(); var divIsOpen = false; //该函数可以创建我们需要的XMLHttpRequest对象 function getHTTPObject() { var xmlhttp = false; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) { xmlhttp.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) { xmlhttp = false; } } } if (!xmlhttp) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } return xmlhttp; } function chkCardNo() { var url = "../chkSfzh?sfzh="+document.getElementById("atCardno").value+"&pd=1"; http.open("GET",url,true); http.onreadystatechange = handleHttpResponse; http.send(null); return; } function handleHttpResponse() { if (http.readyState == 4) { if (http.status == 200) { var htmlDocument = http.responseText; if (htmlDocument!="") { div = getObjectById("div_sfzh"); target = getObjectById("atCardno"); /*层出现的位置*/ findPosition(target,div); /*改写框架内的内容*/ ifr = window.frames("iframe_sfzh"); with(ifr) { document.writeln(htmlDocument); document.close(); } div.style.visibility = "visible"; divIsOpen = true; } else { divIsOpen = false; getObjectById("div_sfzh").style.visibility = "hidden"; } } else { alert("你所请求的页面发生异常,可能会影响你浏览该页的信息!"); alert(http.status); } } } function findPosition(target,div) { var t = target.offsetTop, h = target.clientHeight, l = target.offsetLeft, p = target.type; var o = div.style; while (target = target.offsetParent) {t += target.offsetTop; l += target.offsetLeft;} var cw = parseInt(o.width), ch = parseInt(o.height); var dw = document.body.clientWidth, dl = document.body.scrollLeft, dt = document.body.scrollTop, dh = document.body.clientHeight; if (dh + dt - t - h >= ch) o.top = (p=="image")? t + h : t + h + 6; else o.top = (t - dt < ch) ? ((p=="image")? t + h : t + h + 6) : (t - ch); if (dw + dl - l >= cw) o.left = l; else o.left = (dw >= cw) ? dw - cw + dl : dl; } function hiddenDiv(compare_flag) { if (divIsOpen == true){ if(compare_flag == false){ document.forms[0].atCardno.value=""; document.forms[0].atCardno.focus(); } divIsOpen = false; getObjectById("div_sfzh").style.visibility = "hidden"; } } <td class="tdone" align="right"> 身份证号码 </td> <td class="tdone"> <html:text property="artisanTmp.cardno" styleId="atCardno" οnblur="chkCardNo()"/> <DIV style='position: absolute; z-index: 9999; width: 200px; height: 25px; visibility: hidden' id="div_sfzh"> <IFRAME id="iframe_sfzh" src="../welcome.jsp" mce_src="welcome.jsp" frameborder=0 width=100% height=70% marginheight="0" marginwidth="0"></IFRAME> </DIV> </td> package com.jgc.web.util; import java.io.IOException; import javax.ejb.CreateException; import javax.naming.NamingException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.jgc.ejb.command.CommandException; import com.jgc.ejb.command.view.pm.ViewArtisanTmpsCommand; import com.jgc.ejb.command.view.worker.ViewWorkBasicTempsCommand; import com.jgc.ejb.controller.CommandHandler; import com.jgc.ejb.controller.CommandHandlerHome; import com.jgc.ejb.controller.CommandHandlerUtil; public class ChkSfzh extends HttpServlet { private StringBuffer msgStr = new StringBuffer() ; protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException { String sfzh = request.getParameterValues("sfzh")[0].toString(); String pd = request.getParameterValues("pd")[0].toString(); response.setContentType("text/html;charset=GB2312"); CommandHandlerHome chh; try { chh = CommandHandlerUtil.getHome(); CommandHandler ch = chh.create(); if(pd!=null && pd.equals("1")){//用在项目部人员添加时,是否存在相同的身分证号 ViewArtisanTmpsCommand vatsCommand =new ViewArtisanTmpsCommand(); vatsCommand.initFindByCardno(sfzh); try { vatsCommand = (ViewArtisanTmpsCommand) ch.executeCommand(vatsCommand); } catch (CommandException e1) { } //查找找身份证号为sfzh if(vatsCommand.getArtisans() != null && vatsCommand.getArtisans().size()>0){ //说明存在身份证号,给出提示 msgStr.append("<html><head><link rel=/"stylesheet/" href="/" mce_href="/""../css/main.css/" type=/"text/css/" ></head>" + "<body background=/"../img/sybj.gif/">" + "<table width=/"100%/" class=/"tableone/" cellspacing=/"0/" cellpadding=/"0/">" + "<tr width=/"100%/"><td class=/"tdone/" align=center colspan=2><font color=#FF0000>该身份证号已存在,请重新输入</font></td></tr>"); msgStr.append("<tr><td align=center colspan=2 class=/"tdone/"><a href="javascript:parent.hiddenDiv(false);" mce_href="javascript:parent.hiddenDiv(false);">关闭</a></td></tr>"); msgStr.append("</table></body></html>"); } } msgStr.append(""); response.getWriter().write(msgStr.toString()); msgStr = new StringBuffer(); } catch (IOException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } } protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException { doGet(request,response); } }