学渣要做笔记,学渣要做笔记~~~~
校验器分三部分,在一个做好了的登录界面上进行添加
1.在.jsp中添加,其中的S标签就是添加的,重要的是不要忘了<%@taglib prefix="s" uri="/struts-tags"%>
1 <tr> 2 <td> </td> 3 <td width="11%" height="40" >用户名: </td> 4 <td height="40" colspan="2"> 5 <input type="text" size="20" border="1" name="infor.name"> 6 <s:property value="fieldErrors[‘infor.name‘][0]" /> 7 </td> 8 </tr> 9 <tr> 10 <td> </td> 11 <td width="11%" height="28">密码<img src="<%=request.getContextPath()%>/images/luck.gif" width="19" height="18">: 12 </td> 13 <td height="28" colspan="2"><input type="text" size="20" border="1" name="infor.password"> 14 <s:property value="fieldErrors[‘infor.password‘][0]" /> 15 </td> 16 </tr>
2.在X-x-validation.xml中写校验信息
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE validators PUBLIC 3 "-//OpenSymphony Group//XWork Validator 1.0.3//EN" 4 "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">//是什么版本就写什么版本 5 <validators> 6 <field name="infor.name"> 7 <field-validator type="requiredstring"> 8 <message>用户名不能为空</message> 9 </field-validator> 10 <field-validator type="stringlength"> 11 <param name="minLength">2</param> 12 <param name="maxLength">12</param> 13 <message> 14 账号长度必须在${minLength}~${maxLength}之间 15 </message> 16 </field-validator> 17 </field> 18 19 <field name="infor.password"> 20 <field-validator type="requiredstring"> 21 <message>密码不能为空</message> 22 </field-validator> 23 <field-validator type="stringlength"> 24 <param name="minLength">3</param> 25 <param name="maxLength">12</param> 26 <message> 27 密码长度必须在${minLength}~${maxLength}之间 28 </message> 29 </field-validator> 30 </field> 31 </validators>
3~.Java文件中是用的默认execute(){}方法,那就直接在Struts.xml中加入input跳转的界面
1 <action name="landing" 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>
时间: 2024-11-12 11:57:19