增加用户的时候,当输入用户名称以后,查询该用户是否存在.
1.JSP文件我是这样写的.
$.ajax({ type:'post', url:'${pageContext.request.contextPath}/jsp/squsergl/checkUserAccount.action',//调用的action data:{'userAccount':userAccount,'date':d},//请求的参数 success:function(msg){ if(msg==1) { $("#span1").html("<font color='red'>此用户帐号已被占用</font>"); } if(msg==0) { $("#span1").html("<font color='blue'>此用户帐号可以使用</font>"); } } });
2.struts配置文件很简单
<action name="checkUserAccount" class="squserglAction" method="checkUserAccount"></action>
3.struts的action代码
public void checkUserAccount() throws IOException { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse res=ServletActionContext.getResponse(); String userAccount=request.getParameter("userAccount"); System.out.println(userAccount); List list=squserglService.findCheckUserAccount(userAccount);//查询一下数据库,有没有该用户 if(list.size()>0) { res.getWriter().print(1); } else { res.getWriter().print(0); } }
OK.一个简单的AJAX调用就完成啦!
1 楼
plavip
2010-08-18
你小孩很可爱啊
