当前位置:首页 > 科技 >

jquery ajax struts2用户名验证(get)

发布时间:2017-09-08 23:47:20

jquery ajax struts2用户名验证(get)

jquery ajax struts2用户名验证(get)
页面:
$(document).ready(function(){
checkConfirm();
});
//验证用户名是否存在
function checkConfirm(){
$("#userName").blur(function(){
var gradename = $(this).val();
var changeUrl = "<%=path%>/system/SysOperator/checkUserNameAction.action?inputName="+gradename;
$.get(changeUrl,function(str){
if(str == '1'){
$("#gradeInfo").html("<font color=\"red\">您输入的用户名存在!请重新输入!</font>");
}else{
$("#gradeInfo").html("");
}
})
return false;
})
}

<s:textfield id="userName" label="1" name="userName" maxlength="16" size="16"/>
<font color="red">*</font>
<span id="gradeInfo"></span>
struts2配置文件:
<!-- 用户名称验证 -->
<action name="checkUserNameAction" class="qxUserAction" method="checkUserName">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
struts2Action:
private InputStream inputStream;
private String inputName;
public InputStream getInputStream() {
return inputStream;
}

public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}

public String getInputName() {
return inputName;
}

public void setInputName(String inputName) {
this.inputName = inputName;
}

public String checkUserName(){
// 操作员名称不为空时
if (!StringUtil.isBlank(this.inputName)) {
// 操作员名称不能重复
Long operatorNameCount = this.qxUserService
.checkUserNameExist(this.inputName.trim());

if (operatorNameCount > 0) {
inputStream=new StringBufferInputStream("1");
}else {
inputStream=new StringBufferInputStream("0");
}
}
return SUCCESS;
}

,专题系统,专题系统

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:神农架SEO http://shennongjia.4567w.com