Java 验证器和Struts无法查看错误
我正在研究Struts框架,并尝试一个使用DynaValidator表单的示例。在我的测试中,我尝试在codProdotto字段上添加一个必需的chek。但如果我将文本框留空,则不会显示错误消息 表格: 属性文件Java 验证器和Struts无法查看错误,java,validation,struts-1,struts-validation,Java,Validation,Struts 1,Struts Validation,我正在研究Struts框架,并尝试一个使用DynaValidator表单的示例。在我的测试中,我尝试在codProdotto字段上添加一个必需的chek。但如果我将文本框留空,则不会显示错误消息 表格: 属性文件 # -- validator -- errors.invalid={0} is invalid. errors.maxlength={0} can not be greater than {1} characters. errors.minlength={0} can not be
# -- validator --
errors.invalid={0} is invalid.
errors.maxlength={0} can not be greater than {1} characters.
errors.minlength={0} can not be less than {1} characters.
errors.range={0} is not in the range {1} through {2}.
errors.required={0} is required.
errors.byte={0} must be an byte.
errors.date={0} is not a date.
errors.double={0} must be an double.
errors.float={0} must be an float.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.short={0} must be an short.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
你是否检查了属性文件是否包含关键错误的值。required如下:errors.required=Enter blahTry this nothing…我试图按照你所说的进行更改,但没什么,没有看到消息我正在研究Struts框架-如果你不是为了支持旧版应用而学习Struts,我强烈建议您考虑另一个框架。Struts 1在几年前就已经寿终正寝,支持文档正在消失。用一个死框架开始一个新项目是个坏主意。
<form-bean name="new_product" type="org.apache.struts.validator.DynaValidatorForm" >
<form-property name="codProdotto" type="java.lang.String" />
<form-property name="descrizione" type="java.lang.String" />
<form-property name="categoria" type="java.lang.String" />
<form-property name="numListino" type="java.lang.String" />
<form-property name="prezzo" type="java.lang.Double" />
<form-property name="noteAggiuntive" type="java.lang.String" />
</form-bean>
</form-beans>
<action-mappings>
<action
attribute="new_product"
path="/form_remove_prodotto"
type="controller.ProductManager"
parameter="removeProduct"
name="new_product"
scope="request"
validate="false"
input="input.jsp">
<forward name="ret_index" path="/index.jsp" />
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
<formset>
<!-- An example form -->
<form name="new_product">
<field
property="codProdotto" depends="required">
<arg key="errors.required" />
</field>
</form>
</formset>
</form-validation>
public class ProductManager extends MappingDispatchAction {
public ActionForward addProduct(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
DynaValidatorForm actionForm = (DynaValidatorForm ) arg1;
System.out.println("Add");
return arg0.findForward("ret_index");
}
public ActionForward removeProduct(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
DynaValidatorForm actionForm = (DynaValidatorForm ) arg1;
System.out.println("Remove " + actionForm.get("codProdotto"));
return arg0.findForward("ret_index");
}
}
# -- validator --
errors.invalid={0} is invalid.
errors.maxlength={0} can not be greater than {1} characters.
errors.minlength={0} can not be less than {1} characters.
errors.range={0} is not in the range {1} through {2}.
errors.required={0} is required.
errors.byte={0} must be an byte.
errors.date={0} is not a date.
errors.double={0} must be an double.
errors.float={0} must be an float.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.short={0} must be an short.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.