ActionFrom的验证

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.jlins.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.ValidatorForm;

/**
 * MyEclipse Struts
 * Creation date: 03-08-2008
 *
 * XDoclet definition:
 * @struts.form name="usersForm"
 */
public class UsersForm extends ValidatorForm {
 /*
  * Generated fields
  */

 /** password property */
 private String password;
 
 private String password1;

 /** userName property */
 private String userName;

 /** address property */
 private String address;

 /** email property */
 private String email;

 /** addtime property */
 private String addtime;

 /** tel property */
 private String tel;

 /*
  * Generated Methods
  */

 /**
  * Method validate
  * @param mapping
  * @param request
  * @return ActionErrors
  */
 public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
  // TODO Auto-generated method stub
  ActionErrors errors =new ActionErrors();
  String action =request.getParameter("action");
  if(action.equalsIgnoreCase("save")){
   
  if(userName.trim().equals("")){
    errors.add("userName",new ActionError("errors.userName_is_required"));
  }
  else if(userName.trim().length()>25){
      errors.add("userName", new ActionError("errors.userName_is_duoyu_10"));
  }
  else if(userName.trim().length()<3){
      errors.add("userName", new ActionError("errors.userName_shaoyu_5"));
  }
  if(password.trim().equals("")){
   errors.add("password",new ActionError("errors.password_is_required"));
 }
  else  if(password1!=null)
   if(!password1.equals(password)){
   errors.add("password1",new ActionError("errors.password_is_not_same"));
 }
  if(address.trim().equals("")){
   errors.add("address",new ActionError("errors.address_is_not_null"));
 }
  if(email.indexOf("@")==-1 || email.indexOf(".")==-1)
  {
   errors.add("email",new ActionError("errors.email_type_wrong"));   
 }
  }
  
  return errors;
 }
       
 /**
  * Method reset
  * @param mapping
  * @param request
  */
 public void reset(ActionMapping mapping, HttpServletRequest request) {
  // TODO Auto-generated method stub
 }

 /**
  * Returns the password.
  * @return String
  */
 public String getPassword() {
  return password;
 }

 /**
  * Set the password.
  * @param password The password to set
  */
 public void setPassword(String password) {
  this.password = password;
 }

 public String getPassword1() {
  return password1;
 }

 /**
  * Set the password.
  * @param password The password to set
  */
 public void setPassword1(String password) {
  this.password1 = password;
 }
 /**
  * Returns the userName.
  * @return String
  */
 public String getUserName() {
  return userName;
 }

 /**
  * Set the userName.
  * @param userName The userName to set
  */
 public void setUserName(String userName) {
  this.userName = userName;
 }

 /**
  * Returns the address.
  * @return String
  */
 public String getAddress() {
  return address;
 }

 /**
  * Set the address.
  * @param address The address to set
  */
 public void setAddress(String address) {
  this.address = address;
 }

 /**
  * Returns the email.
  * @return String
  */
 public String getEmail() {
  return email;
 }

 /**
  * Set the email.
  * @param email The email to set
  */
 public void setEmail(String email) {
  this.email = email;
 }

 /**
  * Returns the addtime.
  * @return String
  */
 public String getAddtime() {
  return addtime;
 }

 /**
  * Set the addtime.
  * @param addtime The addtime to set
  */
 public void setAddtime(String addtime) {
  this.addtime = addtime;
 }

 /**
  * Returns the tel.
  * @return Integer
  */
 public String getTel() {
  return tel;
 }

 /**
  * Set the tel.
  * @param tel The tel to set
  */
 public void setTel(String tel) {
  this.tel = tel;
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值