Learning slag to take notes, learn to take notes ~ ~ ~
The validator is divided into three parts, which are added on a well-done login interface.
1. Add in the. JSP, where the s tag is added, it is important not to forget <% @taglib prefix= "s" uri= "/struts-tags"%>
1<tr>2<td> </td>3<TD width= "11%" height= "Nine" > Username: </td>4<TD height= "colspan=" 2 ">5<input type= "text" size= "border=" 1 "name=" Infor.name ">6<s:property value= "fielderrors[' Infor.name '][0]"/>7</td>8</tr>9<tr>Ten<td> </td> One<TD width= "11%" height= "> Password /images/luck.gif "width=" 19 " height= ">: &"nbsp; A</td> -<TD height= "colspan=" 2 "><input type=" text "size=" border= "1" name= "Infor.password" > -<s:property value= "fielderrors[' Infor.password '][0]"/> the</td> -</tr>
View Code
2. Write verification information in X-x-validation.xml
1<?xml version= "1.0" encoding= "UTF-8"?>2<!DOCTYPE validators Public3"-//opensymphony group//xwork Validator 1.0.3//en"4"Http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd" >//What version is written ?5<validators>6<field name= "Infor.name" >7<field-validator type= "Requiredstring" >8<message> user name cannot be empty </message>9</field-validator>Ten<field-validator type= "Stringlength" > One<param name= "MinLength" >2</param> A<param name= "MaxLength" >12</param> -<message> -Account length must be in ${minlength}~between ${maxlength} the</message> -</field-validator> -</field> - +<field name= "Infor.password" > -<field-validator type= "Requiredstring" > +<message> password cannot be empty </message> A</field-validator> at<field-validator type= "Stringlength" > -<param name= "MinLength" >3</param> -<param name= "MaxLength" >12</param> -<message> -Password length must be in ${minlength}~between ${maxlength} -</message> in</field-validator> -</field> to</validators>
View Code
3~. The default execute () {} method used in the Java file is to add the input jump interface directly to the Struts.xml
1 class= "Com.chinasofti.strutshuman.struts.Landing" >2 <result name= "Havelervel1" type= "Dispatcher" >/massage.jsp</result>3 <result name= "Havelervel2" type= "Dispatcher" >/ Massage.jsp</result>4 <result name= "Havelervel3" type= "Dispatcher" >/massage.jsp</ Result>5 <result name= "Havepassword" type= "Dispatcher" >/massage.jsp</result>6 <result name= "input" type= "dispatcher" >/landing.jsp</result>7 </ Action>
View Code
Validator-Filter the submitted user name and password