Home > Back-end >  Struts 2 configuration when the validate method this method does not perform
Struts 2 configuration when the validate method this method does not perform

Time:09-19

Struts. XML:
















LoginAction:

Package com. The action;

The import com. Opensymphony. Xwork2. ActionSupport;
Import the pojo. User;
import java.util.List;
The import com. Dao. *;

Public class LoginAction extends ActionSupport {


private static final long serialVersionUID=1L;

Private String passWord;
private String userName;
Private String mess;

Public String getMess () {
Return mess;
}


Public void setMess (String mess) {
Enclosing mess=mess;
}


Public String getUserName () {
Return the userName.
}


Public void setUserName (String userName) {
Enclosing the userName=userName;
}


Public LoginAction () {}


Public String getPassWord () {
Return the passWord;
}


Public void setPassWord (String passWord) {
Enclosing the passWord=passWord;
}
@ Override
Public String the execute () throws the Exception {
//TODO Auto - generated method stub
The return SUCCESS.
}


@ Override
Public void the validate () {
//TODO Auto - generated method stub
System. The out. Println (" validate ");
If (this. The userName==null) {
Enclosing addFieldError (mess, "user name cannot be empty!!!!!! ");
} else {
If (this. PassWord==null) {
Enclosing addFieldError (mess, "password cannot be empty!!!!!! ");
} else {
UserInfoDao the userInfo=new UserInfoDao ();
List The users=null;
The users=the userInfo. QueryInfo (enclosing the userName);

//query user called the userName of the user whether there is a
If (users. Get (0)==null) {
Enclosing addFieldError (mess, "the user does not exist!" );
} else if (this. The passWord!=the users. The get (0). GetPassWord ()) {
Enclosing addFieldError (mess, "password is not correct!!! ");
}
}
}
}




Login interface: index. The JSP

  • Related