When validating data using the XML configuration of struts, it was found to be ineffective. Unable to follow normal process, go to the page where input points.
A solution to a problem
Many blogs explain the way they look, and finally point to the reason why the configuration file is not properly formatted. This problem should be considered in the following 4 sections:
1: Whether the file name is Loginaction-validation.xml the first part of the name must match the action class name.
Under the same action in 2:struts.xml, to configure the return result of the input type, as follows:
<action name= "Login" class= "Com.allen.ssh.action.LogInAction" >
<result name= "Success" >/Welcome.jsp</result>
<result name= "Error" >/Register.jsp</result>
<result name= "Input" >/Register.jsp</result>
</action>
3: Then check the name of the property specified in Loginaction-validation.xml, and whether it matches the property name in the JSP page.
4: Then the Loginaction-validation.xml file format is correct, mainly refers to the following part:
<! DOCTYPE validators Public
"-//apache struts//xwork Validator 1.0.3//en"
"Http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd" >
The root of the two problems
There is a certain development experience of children's shoes, no matter how the steps, will be the overall check down, because this check file as long as the action class in the same package, is automatically loaded, do not care if you want to configure where.
But I want to say is the cause of this problem, in general, everyone is to search for an article, and then do the example, but sometimes the use of struts version inconsistent, rushed to use a different version of the configuration, it is likely to cause this problem.
So, refer to what others do, the main thing is to see the idea, specific to their own to achieve, to go to their own download of the source package below, to find the corresponding file: struts-2.3.16.3/src/xwork-core/src/main/resources/ Xwork-validator-1.0.3.dtd
Open and look, it says:
<!--
Xwork validators DTD.
used the following DOCTYPE.
</pre><p></p><p></p><pre name= "code" class= "HTML" > <! DOCTYPE validators Public
"-//apache struts//xwork Validator 1.0.3//en"
"Http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd" >
-
Then a direct copy of the past can be used. Be aware that the 1.0.2 version is also configured as follows:
</pre><pre>
<! DOCTYPE validators Public "-//opensymphony group//xwork Validator 1.0.2//en"
"Http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd" >
So whether you use it directly or modify it to 1.0.3, it will cause the checksum to not work.
Three development recommendations
As can be seen from this question, when using the open source framework, be sure to use the software itself with the example configuration file description, rather than directly to the network copy. This should be a long-established habit.
Finally, take strtus as an example, the relevant DTD file, typically in the following package:
struts-2.3.16.3/src/
If it's validator:struts-2.3.16.3/src/xwork-core/src/main/resources/xwork-validator-1.0.3.dtd,
If it is a tag library:/USERS/ZHAOXIN/DEV/STRUTS-2.3.16.3/SRC/CORE/SRC/MAIN/RESOURCES/STRUTS-2.3.DTD