简体   繁体   中英

How to perform Java bean validation with error messages? *in JSP not JSF

I searched all over SO but every thing seems to refer to JSF. Its JSP that im in need of help with. I have a form and a bean

private String email;
public String getEmail() { return email; }    
public void setEmail( String email ) { this.email = email; }

I would like to know how to validate this field and return an error to the form if not valid , if I could keep previous valid fields intact would be great also, I'm really not grasping this.

i have tried this to no avail

@NotNull @Email 
  public String getEmail() { return email; }
  public void setEmail(String email) { 
  this.email = email; 
}
private String email;

}

So, to actually provide an answer on top of my comment which was meant to put a few facts in order, if you want to get bean validation going without having any web framework to manage it for you, this means you'll need to download an implementation of the bean validation API, read its manual and apply it.

http://beanvalidation.org/1.1/ri/

The reference implementation is Hibernate Validator - which is of course closely tied to the Hibernate ORM package but can be used separately as well.

http://hibernate.org/validator/

There are probably other implementations as well, but SO is not a tool recommendation site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM