分类: Java
2008-04-08 13:40:26
1、 在struts-config下添加如下代码:
xml version="1.0" encoding="UTF-8"?>
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "">
<struts-config>
<form-beans >
<form-bean name="myForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="uid" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
<form-property name="name" type="java.lang.String"/>
form-bean>
form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="myForm"
input="/user.jsp"
validate="true"
name="myForm"
path="/user"
scope="request"
type="com.sailor.struts.action.UserAction"
>
<forward
name="success"
path="/view.jsp"
redirect="true" />
<forward
name="fail"
path="/error.jsp"
redirect="true" />
action>
action-mappings>
<message-resources parameter="com.sailor.struts.ApplicationResource_zh_CN"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml"/>
plug-in>
struts-config>
2 在WEB-INF下新建一个validation.xml
DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration
"">
<form-validation>
<formset>
<form name="myForm">
<field property="uid" depends="required">
<arg key="uid"/>
field>
<field property="password" depends="required,maxlength,minlength">
<arg key="password"/>
<arg key="${var:minlength}" name="minlength" resource="false"/>
<arg key="${var:maxlength}" name="maxlength" resource="false"/>
<var>
<var-name>minlengthvar-name>
<var-value>6var-value>
var>
<var>
<var-name>maxlengthvar-name>
<var-value>10var-value>
var>
field>
form>
formset>
form-validation>
3 在国家化标签中添加如下:
4 在user.jsp中添加
经过以上步骤就可以实现简单的用户身份验证。
|
|