today, take some time to review, Li Gang <<struts2 authoritative guide >>, which has a chapter on client-side validation, follow the steps in the book, Finally reported a Freemarker.template.TemplateModelException:Method public java.util.List error,
Problem: When using struts for client-side validation, add the validate= "true" attribute to the form, and the login.jsp code is as follows:
<s:form action= "Useraddaction" method= "POST" validate= "true" >
<s:textfield name= "username" key= "username" ></s:textfield>
<s:textfield name= "FirstName" key= "FirstName" ></s:textfield>
<s:submit key= "Login" ></s:submit>
</s:form>
Intercept some error codes
------------------------------------------------------
Exception code:
2011-8-9 17:14:33 Freemarker.log.jdk14loggerfactory$jdk14logger Error
Serious:
Method public java.util.List org.apache.struts2.components.Form.getValidators (java.lang.String) threw an exception When invoked on [email protected]
The problematic instruction:
----------
==> list tag.getvalidators ("${tagname}") as validator [on line +, column 9 in TEMPLATE/XHTML/FORM-CLOSE-VALIDATE.FTL]
In include '/${PARAMETERS.TEMPLATEDIR}/XHTML/FORM-CLOSE-VALIDATE.FTL ' [on line, column 1 in template/xhtml/ FORM-CLOSE.FTL]
----------
Java BackTrace for programmers:
----------
Freemarker.template.TemplateModelException:Method Public Java.util.List Org.apache.struts2.components.Form.getValidators (java.lang.String) threw an exception when invoked on [email protected ]
At Freemarker.ext.beans.SimpleMethodModel.exec (simplemethodmodel.java:130)
.........
------------------------------------------------------
in the spirit of the matter asked the mother, foreign affairs do not decide to ask Google's attitude, found someone said
Workaround 1:
Remove the Validate= "true" attribute from the form, which cancels the client-side validation of the STRUTS2 framework and instead, it authenticates the server. This is not the solution to the problem, hehe!
Workaround 2: Add a suffix to the action. The action solves the problem, and the modified login.jsp code is as follows:
<s:form action= "Useraddaction.action" method= "POST" validate= "true" >
<s:textfield name= "username" key= "username" ></s:textfield>
<s:textfield name= "FirstName" key= "FirstName" ></s:textfield>
<s:submit key= "Login" ></s:submit>
</s:form>
But Method 2 will report another error
2015-3-10 11:48:29 Com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
Warning: No configuration found for the specified action: 'useraddaction. Action ' in namespace: '/login '. Form action defaulting to ' action ' attribute ' s literal value.
2015-3-10 11:48:29 Com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
Warning: No configuration found for the specified action: 'useraddaction. Action ' in namespace: '/login '. Form action defaulting to ' action ' attribute ' s literal value.
Solution 3: Fill in the Struts.xml with a
<action name= "Logininit" class= "Com.tungkong.action.RegistAction" >
<result name= "Input" >/login.jsp</result>
<result name= "Success" >/success.jsp</result>
</action>
The login.jsp code is as follows:
<s:form action= "Useraddaction" method= "POST" validate= "true" >
<s:textfield name= "username" key= "username" ></s:textfield>
<s:textfield name= "FirstName" key= "FirstName" ></s:textfield>
<s:submit key= "Login" ></s:submit>
</s:form>
Visit the time to write: http://localhost:8080/test/logininit, so will not error, if there is a better way to solve, you are welcome to discuss!
Struts2 freemarker.template.TemplateModelException