那好Struts有什么相关的。如果用Struts的话,在FormBean里验证即可,如下:
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;public class CustomerRegisterForm extends ActionForm {
private String customerName = null;
private String customerPassword = null;
private String customerTelephone = null;
private String recommendBuySalesmanId = null;
private String receiverName = null;
private String receiverPhone = null;
private String receiverAddress = null;
private String receiverZipcode = null;

/**
 * Constructor
 *
 */
public CustomerRegisterForm() {
super();
}

public void setCustomerName( String customerName ) {
this.customerName = customerName;
}

public void setCustomerPassword( String customerPassword ) {
this.customerPassword = customerPassword;
}

public void setCustomerTelephone( String customerTelephone ) {
this.customerTelephone = customerTelephone;
}

public void setRecommendBuySalesmanId( String recommendBuySalesmanId ) {
this.recommendBuySalesmanId = recommendBuySalesmanId;
}

public void setReceiverName( String receiverName ) {
this.receiverName = receiverName;
}

public void setReceiverPhone( String receiverPhone ) {
this.receiverPhone = receiverPhone;
}

public void setReceiverAddress( String receiverAddress ) {
this.receiverAddress = receiverAddress;
}

public void setReceiverZipcode( String receiverZipcode ) {
this.receiverZipcode = receiverZipcode;
}

public String getReceiverZipcode() {
return this.receiverZipcode;
}

public String getReceiverAddress() {
return this.receiverAddress;
}

public String getReceiverPhone() {
return this.receiverPhone;
}

public String getReceiverName() {
return this.receiverName;
}

public String getCustomerName() {
return this.customerName;
}

public String getCustomerPassword() {
return this.customerPassword;
}

public String getCustomerTelephone() {
return this.customerTelephone;
}

public String getRecommendBuySalesmanId() {
return this.recommendBuySalesmanId;
}

/**
 * Validate the properties that have been sent from the HTTP request,
 * and return an ActionErrors object that encapsulates any
 * validation errors that have been found. If no errors are found, return
 * an empty ActionErrors object.
 */
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
 
    if( getCustomerName() == null || "".equals(getCustomerName())
     || getCustomerTelephone() == null || "".equals(getCustomerTelephone())
|| getRecommendBuySalesmanId() == null || "".equals(getRecommendBuySalesmanId())
|| getReceiverName() == null || "".equals(getReceiverName()) 
|| getReceiverPhone() == null || "".equals(getReceiverPhone()) 
|| getReceiverAddress() == null || "".equals(getReceiverAddress())
|| getReceiverZipcode() == null || "".equals(getReceiverZipcode()) ) {
     errors.add( "register",
     new ActionError("error.type.required") );
    }
    
    if( getCustomerPassword() == null || "".equals(getCustomerPassword()) ) {
     errors.add( "password",
     new ActionError("error.password.required") );
    }
    else if( getCustomerPassword().length() < 8 ) {
     errors.add( "passwordNum",
     new ActionError("error.passwordNum.required") );
    }     return errors;
}

/**
 * 
 */
public void reset(ActionMapping mapping, HttpServletRequest request) {
    /** Because this ActionForm should be request-scoped, do nothing here.
     *  The fields will be reset when a new instance is created. We could 
     *  have just not overriden the parent reset(  ) method, but we did so
     *  to provide an example of the reset(  ) method signature.
     */
this.customerName = null;
this.customerPassword = null;
this.customerTelephone = null;
this.recommendBuySalesmanId = null;
this.receiverName = null;
this.receiverPhone = null;
this.receiverAddress = null;
this.receiverZipcode = null;
}
}