Struts2 freemarker.template.TemplateModelException

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.