1 17 package examples; 18 19 import org.apache.struts.action.*; 20 21 import javax.servlet.http.HttpServletRequest ; 22 23 public class LoginForm extends ActionForm { 24 25 private String username; 26 private String password; 27 28 public void setUsername(String username) { 29 this.username = username; 30 } 31 32 public String getUsername() { 33 return this.username; 34 } 35 36 public String getPassword() { 37 return this.password; 38 } 39 40 public void setPassword(String password) { 41 this.password = password; 42 } 43 44 public ActionErrors validate(ActionMapping mapping, 45 HttpServletRequest request) { 46 ActionErrors errors = new ActionErrors(); 47 if ((username == null) || (username.length() < 1)) 48 errors.add("username",new ActionMessage("error.username.required")); 49 if ((password == null) || (password.length() < 1)) 50 errors.add("password",new ActionMessage("error.password.required")); 51 if (errors.isEmpty()) 52 return null; 53 else 54 return errors; 55 } 56 57 } 58 59 | Popular Tags |