Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Struts 2验证错误_Java_Validation_Struts2 - Fatal编程技术网

Java Struts 2验证错误

Java Struts 2验证错误,java,validation,struts2,Java,Validation,Struts2,在尝试添加标识时,我希望验证标识名称是否为空,我在xml文件designation-validation.xml中使用了以下代码 <field name="desgName"> <field-validator type="requiredstring"> <message>Please enter designation name</message> </field-validator> </fi

在尝试添加标识时,我希望验证标识名称是否为空,我在xml文件designation-validation.xml中使用了以下代码

<field name="desgName">
    <field-validator type="requiredstring">
        <message>Please enter designation name</message>
    </field-validator>
</field>


请输入指定名称

但它不起作用,它正在我的数据库中添加一个空的名称。但它在我的控制台中显示以下行

2011年3月30日下午3:17:18 com.opensymphony.xwork2.util.logging.commons.commonlogger错误 严重:设计名称的验证错误:请输入指定名称


有人能帮忙吗?提前感谢…

根据日志,字段验证正在工作,并且由于您尚未指定“trim”参数,默认情况下,字符串将在长度检查为零之前进行修剪,因此验证应按照您的意愿进行,在提交表单时似乎会被忽略

其他现场验证是否有效?这可能是由于配置问题造成的。您是否在JSP中使用了

检查此处,了解如何设置所有设置,以防您遗漏某些内容-


验证规则
ActionName Validation.xml

应该是
指定动作验证.xml

或者,确保操作具有扩展的ActionSupportActionSupport的子类

// Action
public class DesignationAction extends ActionSupport{ 
  @Getter @Setter private String desgName;
}  

@voidnull,该页中的所有字段均不进行验证。是的,我在jsp文件中使用了。@shinod-您是否检查了工作流拦截器的配置是否正确?工作流拦截器检查是否存在验证错误,如果发现任何错误,则将用户带回包含验证错误的表单。请看这里-如果您可以添加jsp的代码struts.xml,那就太好了。action类也不会有任何问题。我没有扩展ActionSupport或ActionSupport的子类。但是我不明白验证需要ActionSupport。@shinod可以说验证需要ActionSupport。请参阅和的API