< Spring:bind Path = "Command.name" >
Name: < input type = "text" name = "Name" value = "<c:out value=" ${status.value} "/>"/> (must be entered)
< C:if test = "${status.error}" >
< font color = "#FF0000" >
Error:
< C:foreach items = "${status.errormessages}" var = "error" >
< C:out value = "${error}"/>
</C:foreach >
</font >
</c:if >
</spring:bind > < Spring:bind path = "Command.name" >
Name: < input type = "text" name = "Name" value = "<c:out value=" ${status.value} "/>"/> (must be entered)
< C:if test = "${status.error}" >
< font color = "#FF0000" >
Error:
< C:foreach items = "${status.errormessages}" var = "error" >
< C:out value = "${error}"/>
</C:foreach >
</font >
</c:if >
</spring:bind >
Spring MVC provides us with a validation framework similar to Struts validator, but spring does not write XML validation files, and it is the validator interface provided by the implementation period itself, providing our Pojo JavaBean with specific classes of validation. Very convenient, below, we will be together to achieve this function
First of all, we first write a registration page, only two fields, name and gender, here requires the name and gender must be entered, and gender can only enter 0 or 1
register.jsp
<% ... @ Page language= "java" import= "java.util.*" pageencoding= "GB18030"%>
<% @ taglib prefix= "Spring" uri= "Http://www.springframework.org/tags"%>
<% @ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
< HTML >
< head >
< BODY >
< Spring:bind Path = "command.*" >
< font color = "#FF0000" >
< C:foreach items = "${status.errormessages}" var = "error" >
Error: < C:out value = "${error}"/>< br >
</C:foreach >
</font >
</spring:bind >
< form action = "<%=request.getcontextpath ()%>/register.mvc" method = "POST" >
< Spring:bind Path = "Command.name" >
Name: < input type = "text" name = "Name" value = "<c:out value=" ${status.value} "/>"/> (must be entered)
< C:if test = "${status.error}" >
< font color = "#FF0000" >
Error:
< C:foreach items = "${status.errormessages}" var = "error" >
< C:out value = "${error}"/>