RegisterAction-test-validation.xml 验证文件
=========================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<validator type="requiredstring">
<param name="fieldName">username</param>
<param name="fieldName">password</param>
<message>${fileName} not field should not be blank</message>
</validator>
<validator type="stringlength">
<param name="fieldName">username</param>
<param name="fieldName">password</param>
<param name="min">6</param>
<param name="max">10</param>
<message>${fieldName} should ${min} to ${max}</message>
</validator>
</validators>
================================================================
struts.xml文件 如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org./dtds/struts-2.0.dtd">
<struts>
<constant name="struts.custom.il8n.resources" value="message"></constant>
<package name="struts2" extends="struts-default">
<interceptors>
<interceptor name="MyInterceptor" class="com.test.interceptor.MyInterceptor">
<param name="myParams">i am params</param>
</interceptor>
</interceptors>
<action name="PointConverter" class="com.test.action.PointAction">
<result name="success">/output.jsp</result>
<result name="input">/input.jsp</result>
</action>
<action name="register" class="com.test.action.RegisterAction"
method="test">
<result name="success">/success.jsp</result>
<result name="input">/register2.jsp</result>
<interceptor-ref name="MyInterceptor"></interceptor-ref>
</action>
</package>
</struts>
================================================================================
*:这个时候以前书写的验证文件就不起作用。原因是 interceptor 只能有一个默认的interceptor 就是defaultStack 在struts-default.xml 中
修改struts.xml文件 我这里用一个interceptor-stack 拦截器栈 跟问题本身没有关系,如下
=============================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org./dtds/struts-2.0.dtd">
<struts>
<constant name="struts.custom.il8n.resources" value="message"></constant>
<package name="struts2" extends="struts-default">
<interceptors>
<interceptor name="MyInterceptor" class="com.test.interceptor.MyInterceptor">
<param name="myParams">i am params</param>
</interceptor>
<interceptor-stack name="myInterceptorStack">
<interceptor-ref name="MyInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="PointConverter" class="com.test.action.PointAction">
<result name="success">/output.jsp</result>
<result name="input">/input.jsp</result>
</action>
<action name="register" class="com.test.action.RegisterAction"
method="test">
<result name="success">/success.jsp</result>
<result name="input">/register2.jsp</result>
<interceptor-ref name="myInterceptorStack"></interceptor-ref>
</action>
</package>
</struts>
这下以前用xml 书写的验证就都好使啦