Jquery ajax struts2 user name verification (get)
Page:
$ (Document). ready (function (){
CheckConfirm ();
});
// Verify whether the user name exists
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 \ "> the user name you entered exists! Enter again! </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 configuration file:
<! -- User Name verification -->
<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 (){
// When the operator name is not blank
If (! StringUtil. isBlank (this. inputName )){
// The Operator name cannot be repeated.
Long operatorNameCount = this. qxUserService
. CheckUserNameExist (this. inputName. trim ());
If (operatorNameCount> 0 ){
InputStream = new StringBufferInputStream ("1 ");
} Else {
InputStream = new StringBufferInputStream ("0 ");
}
}
Return SUCCESS;
}