struts2 form标签加上validate="true"就出错的解决办法

背景说明:

我用的是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,明白的朋友请留言。

posted on 2011-08-02 10:22  大凡不诛仙  阅读(3214)  评论(0编辑  收藏  举报

导航