struts2 form标签加上validate=true就出错的解决办法
http://www.cnblogs.com/dafanjava/archive/2011/08/02/2124681.html
背景說明:
我用的是struts2.2.3
相關源碼:
<s:form action="addBook" validate="true"><!-- form標簽,啟用驗證 --> 加上validate="true"就報下面的錯誤
<s:label value="form標簽"></s:label>
<s:textfield name="name" label="書名"></s:textfield>
<s:textfield name="author" label="作者"></s:textfield>
<s:submit value="提交" align="center"></s:submit>
</s:form>
報如下錯誤:
嚴重: Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@19c6163
Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@19c6163
The problematic instruction:
----------
==> list tag.getValidators("${tagName}") as validator [on line 46, column 9 in template/xhtml/form-close-validate.ftl]
in include "/${parameters.templateDir}/xhtml/form-close-validate.ftl" [on line 25, 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 org.apache.struts2.components.Form@19c6163
(此處略去其他詳細的exception信息)
Caused by: java.lang.NullPointerException
(此處略去其他詳細的exception信息)
嚴重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException?
(此處略去其他詳細的exception信息) ?
解決辦法:
法一:
去掉validate="true"
不過我想這種辦法不是你想要的(反正我是不希望這樣解決),所以我采用第二種辦法。
法二:
將form標簽的name屬性改成"addBook.action" ,即改為:<s:form action="addBook.action" validate="true"></form>
問題解決,但是我也不知道為什么需要加.action,明白的朋友請留言。
?
總結
以上是生活随笔為你收集整理的struts2 form标签加上validate=true就出错的解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 外地买房,提取公积金
- 下一篇: OGNL是Object-Graph Na