<script type="text/javascript">
<!--
var __ajaxRequest=false;
var __inited=false;
var __container=false;
function __init(){
__inited=true;
if(window.ActiveXObject){
try{
__ajaxRequest=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
__ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");
}catch(ee){
}
}
}
if(!__ajaxRequest){
alert("can't init");
}else{
__ajaxRequest.onreadystatechange=function(){
if(__ajaxRequest.readyState==4){
if(__ajaxRequest.status==200){
confirmDiv.innerText=__ajaxRequest.responseText;
}
}
};
__ajaxRequest.open("POST","/JBlog/common/registe.do?action=checkUserName",true);
__ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
}
function __sendData(){
if( userRegForm.userName.value == ""){
confirmDiv.innerText = "请先填写用户名";
return ;
}
__init();
var data = "userName="+ userRegForm.userName.value;
__ajaxRequest.send(data);
}
//-->
</script>
<tr>
<td width="20%" align="right">用户名:</td>
<td align="center"><html:text property="userName" />
<td style="color: #ff0000;width: 40%;">*</td>
</tr>
<tr>
<td align="right"></td>
<td align="center"><a href="javascript:__sendData()">检查用户名是否可用</a></td>
<td><div id="confirmDiv"></div></td>
</tr>
.java文件
String name = request.getParameter("userName");
String result = "";
if( checkUserExists(name) ) {
result = getResources(request, "abc").getMessage("已存在此用户名");
} else {
result = getResources(request, "abc").getMessage("此用户名未被使用");
}
try {
response.setContentType("text/html; charset=gb2312");
response.getWriter().println(result);
}catch(Exception e) {
e.printStackTrace();
}
public checkUserExists(String name){
验证
}