日期:2014-05-16 浏览次数:20680 次
<script language="javascript"> var http_request = false; function t1(){ var userName = document.all("um.userName").value; //alert(userName); //ajax开始----------------------------- //1:创建对象 myRequest = new ActiveXObject("Microsoft.XMLHTTP"); //2:给该对象注册事件,当对象的状态改变时,调用后面的回调方法 //alert(myRequest.readyState); myRequest.onreadystatechange = t2; //3:设置请求方式、目标url以及是否异步交互,其中true表示异步 myRequest.open("GET","/s2/user/myAction?uwm.submitFlag=toAdd&um.userName="+userName,true); //4: myRequest.send(null); } function t2(){ //alert(myRequest.readyState); if(myRequest.readyState==4){ //如果交互完成 //alert(myRequest.status); if(myRequest.status==200){ //并且交互成功 //取得服务端返回的信息 var retVal = myRequest.responseText; //ajax结束----------------------------- //alert(retVal); //后续处理 document.all("myspan").innerHTML=retVal; } } } </script> <body> <form name="add" action="/s2/user/myAction.action?uwm.submitFlag=add" method="post"> <table align="center"> <tr> <td colspan="2"><font size="+1" color="#ff00ss">添加用户</font></td> </tr> <tr> <td>用户姓名:</td> <td><input type="text" name="um.userName" onblur="t1()"/><font color="red">*<span id="myspan"></span></font></td> </tr>
public String execute() throws Exception { String submitFlag = uwm.getSubmitFlag(); //System.out.println(submitFlag); if(submitFlag!=null){ if("toAdd".equals(submitFlag)){ return toAdd(); } } private String toAdd() throws IOException { String userName = um.getUserName(); qum.setUserName(userName); Collection col = UserServiceFactory.getUserService().getUserByCondition(qum); if(col.size()==0){ return "yes"; }else{ return "no"; } }
<result name="yes">/pages/yes.jsp</result> <result name="no">/pages/no.jsp</result>
恭喜,此用户名可用!//yes.jsp sorry,此用户名已存在,请重新输入!//no.jsp