首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

关于Ajax的运用

2012-08-09 
关于Ajax的使用这是jsp代码%@ page languagejava importjava.util.* pageEncodingutf-8%%@ ta

关于Ajax的使用
这是jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  <title> -注册新用户- </title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/register.css"/>">
<script type="text/javascript" src="<c:url value='/js/validate.js'/>"></script>
  <script type="text/javascript" src="<c:url value='/js/prototype.js'/>"></script>  

 <script type="text/javascript">
   
  function userValidate(){
with(document.userForm){
if(mno.value==""){
alert("请填写用户名!");
return false;
}
if(mno.value.length<3||mno.value.length>15){
alert("用户名长度必须是在3-15之间,请重新输入");
return false;
}
if(mpwd.value==""){
alert("请输入密码!");
return false;
}
if(cmpwd.value==""){
alert("请确认密码!");
return false;
}
if(mpwd.value.length<3||mpwd.value.length>15){
alert("密码长度必须是在3-15之间,请重新输入");
return false;
}
if(mpwd.value!=cmpwd.value){
alert("前后密码不一致!");
return false;
}
if(mname.value==""){
alert("请填写真实姓名!");
return false;
}
if(mname.value.length<2||mname.value.length>10){
alert("请输入长度2-10的中文名!");
return false;
}
if(mbirthday.value==""){
alert("请填写出生日期!");
return false;
}
if(mmail.value==""){
alert("请填写电子邮箱!");
return false;
}
if(mphone.value==""){
alert("请填写电话号码!");
return false;
}
if(maddr.value==""){
alert("请填写地址!");
return false;
}
if(maddr.value.length>100){
alert("地址长度应小于100个字符!");
return false;
}
if(mpostcode.value==""){
alert("请填写邮编!");
return false;
}
if(mpostcode.value.length!=6){
alert("邮编长度必须为6!");
return false;
}
}

return true;
}
 
function checkMNo(){
 
var mNo=$('mno').value;
alert(mNo);

//alert("magMgr?act=searchUser&mno="+mNo.value);
 
new Ajax.Request(
  encodeURI("userMgr?act=searchUser&seed="+Math.random()+"&uno="+mNo),
  {
  method:"get",
  onComplete:function(xhr){
  if(xhr.responseText==""){ 
  $('mtip').innerText="此用户名,未被注册,可以使用!";  
  return;
  }
  else{
  $('mtip').innerText="此用户名已被注册,可请换一个!";  
  return;
  }  


  }
  }  
  );
}
  </script>


  </head>
  
  <body>
  <center>
<FORM id=form name="userForm" action="<c:url value='/userMgr?act=createUser'/>" method=post onsubmit="return userValidate();">
<!-- 注册头部 -->
<DIV class=ddlogin_head_frame>
  <DIV class=ddlogin_head>
  <A href="#" target=_blank>
  <IMG title=当当logo src="<c:url value="/pics/head.png"/>">
  </A> 

</DIV>
</DIV>
<!-- 注册内容区 begin -->
<DIV class=login_frame>
<UL class=login_tag style="margin-left:5px;">
<LI class=tag_one_now>填写注册信息 </LI>
<LI class=tag_two><SPAN class=f_Arial>2.</SPAN> 邮箱验证 </LI>
<LI class=tag_three><SPAN class=f_Arial>3.</SPAN> 完成注册 </LI>
</UL>

<DIV class=login_true>
<UL class=login_ul>
<LI>
<SPAN class=span_n>
<SPAN class=f_Arial>用户名:</SPAN>
</SPAN>
<INPUT class=input_text type="text" id="mno" name="mno" value="${param.UNo}" onchange="checkMNo();"> 
<em id="mtip"> 必填,且必须是英文字母或数字, 长度3-15</em> 
 
</LI>

<LI>
<SPAN class=span_n>设定密码:</SPAN>
<INPUT class=input_text type=password name="mpwd"/> <em>必填,且长度3-15</em>
</LI>
<LI>
<SPAN class=span_n>确认密码:</SPAN>
<INPUT class=input_text type=password name="cmpwd"/> <em>必填,且长度3-15</em>
</LI>

<LI>
<SPAN class=span_n>
<SPAN class=f_Arial>真实姓名:</SPAN>
</SPAN>
<INPUT class=input_text type="text" name="mname" value="${param.UName}"/> <em>必填,中文,2-10个字符</em>  
</LI>

<LI>
<SPAN class=span_n>
<SPAN class=f_Arial>出生日期:</SPAN>
</SPAN>
<INPUT class=input_text type="text" name="mbirthday" value="${param.UBirthday}"/> <em>必填,格式:yyyy-mm-dd</em>  
</LI>

  <LI>
<SPAN class=span_n>
<SPAN class=f_Arial>电子邮箱:</SPAN>
</SPAN>
<INPUT class=input_text type="text" name="mmail" value="${param.UMali}"/> <em>必填 </em>
</LI>
  <LI>
<SPAN class=span_n>
<SPAN class=f_Arial>电话号码:</SPAN>
</SPAN>
<INPUT class=input_text type="text" name="mphone" value="${param.UPhone}"/> <em>必填,且是数字</em>
</LI>
  <LI>
<SPAN class=span_n>
<SPAN class=f_Arial>邮编:</SPAN>
</SPAN>
<INPUT class=input_text type="text" name="mpostcode" value="${param.UPostCode}"/> <em>必填,且是6位数字</em>
</LI>
  <LI>
<SPAN class=span_n>
<SPAN class=f_Arial>地址:</SPAN>


</SPAN>
<INPUT class=input_text type="text" name="maddr" size="50" value="${param.UAddr}"/> <p>必填,长度不能大于100</p>
</LI>
<LI >
<div style="FLOAT: left; FONT-SIZE: 14px; ">
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <SPAN >性别:</SPAN>
<INPUT type="radio" name="msex" value="M" checked <c:if test="${param.USex=='M'}">checked</c:if> />男
  <input type="radio" name="msex" value="F" <c:if test="${param.USex=='F'}">checked</c:if> />女
  </div>
  &nbsp &nbsp &nbsp &nbsp <em style="FLOAT: center;">请选择性别</em>
</LI>

</UL>
<span></span>
<span></span>
<span></span>
<INPUT class=login_tj id=click_submit type=submit name=btn_register value="提 交 注 册">
</DIV>
</DIV>
<br>

<!--注册内容区 end-->
<!--预留页尾位置-->
<DIV style="MARGIN: auto; WIDTH: 962px">
<!--页尾 开始 -->
<div style="clear:both;"></div>
</FORM>
</center>

<div id="footer">
<%@ include file="/jsps/footer.jsp"%>
</div>
  </body>
</html>  


<!--------------------------------------
以上是jsp页面的代码。我用的是EJB技术,软件MyEclipse6.5。问题是:要注册时,我用Ajax判断数据库是否已存在该账户,但是每次输入帐号后,Ajax没有进入encodeURI的地址(我在后台servlet设置断点,没有进入),而直接给我当成返回null处理,因此每次提示都是写该用户已存在,可是后台数据库明明没有该用户帐号。不知道这是什么原因,求高手帮助,万分感谢!!

[解决办法]
sync:true

热点排行