我用Struts2写一个验证器要求验证用户名不得为空等等,但是那些验证都显示不出来求各位大神指点指点。
login2Action.java
package cn.edu.xmut.action;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class Login2Action extends ActionSupport{
private static final long serialVersionUID = 1L;
private String username;
private String password;
public String login(){
return Action.SUCCESS;
}
// @Override
// public void validate() {
// if(username == null || "".equals(username)){
// this.addFieldError("username",this.getText("username.null"));
// }
// if(password == null||"".equals("password")){
// this.addFieldError("password",getText("password.null"));
// }
// }
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
login2.jsp
struts.xml
LoginAction-validation.xml