日期:2014-05-16 浏览次数:20365 次
前台jsp页面:
function docheck(){ var cellno = document.getElementById("filterNo").value; var cellno2 = cellno.trim(); var reg_tel = /^1[3-9]{1}\d{9}$/; if(!reg_tel.test(cellno2)){ showAlert(cellno+"不是合法手机号码"); $("#advice").html(""); $("#filterNo").focus(); $("#filterNo").addClass("lpm"); return false; } var urlStr = "<%=basepath %>/smsfilter/smsFilter-check.action"; $.ajax( { type : "POST", url : urlStr, data : "cellno="+cellno2, success : executeCheck // 回调函数 }); } // 回调函数 function executeCheck(ss) { if(ss=="1"){ $("#advice").html("<p>该手机号码已在黑名单中</p>"); $("#filterNo").focus(); $("#filterNo").addClass("lpm"); }else{ $("#advice").html(""); document.forms[0].submit(); } }
?action类:
@Namespace("/smsfilter") public class SmsFilterAction extends BaseAction{ @Action(value="smsFilter-check", results={@Result(name="add",location="smsFilter-add.jsp")}) public String check()throws Exception { HttpSession session = getHttpRequest().getSession(); TEnterpriseInfo entInfo = (TEnterpriseInfo)session.getAttribute("entInfo"); TUserTeInfo userinfo = (TUserTeInfo)session.getAttribute("userInfo"); int userId = Integer.parseInt(userinfo.Id) ; int entId = Integer.parseInt(entInfo.Id); String telno=getHttpRequest().getParameter("cellno"); //获得jsp页面的cellno的值 SmsfilterServiceInter tsi = ServiceFactory.getSmsfilterService(); try{ int check = tsi.getSmsFiltersCheck(userId, entId,telno); PrintWriter pw=getHttpResponse().getWriter(); pw.print(check); }catch(Exception e){ e.printStackTrace(); } return null; } }
service层的方法:
public int getSmsFiltersCheck(int userId, int entId,String telno) throws Exception { SmsfilterDao sdaoc = new SmsfilterDao(); return sdaoc.getSmsFiltersCheck(userId, entId, telno); }
dao层的方法:
public int getSmsFiltersCheck(int userId,int entId,String telno) throws Exception{ String hql="from Smsfilter f where f.userId="+userId+" and f.entId="+entId+" and f.smsTelNo='"+telno+"'"; List list=query(hql); if(list==null){ return 0; }else{ return 1; } }
?