关于Struts显示错误信息的方法:
都知道Struts中表单验证错误信息需要编辑com.工程名.struts下的ApplicationResources.properties文件,但是我不知道怎么编辑。
比如,我在登录界面的验证表单中有以下代码:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(userid==null&&userid.trim().length()<1){
errors.add("UserIDIsNull", new ActionMessage("UserIDIsNull"));
}
if(password==null&&password.trim().length()<1){
errors.add("PasswordIsNull", new ActionMessage("PasswordIsNull"));
}
return errors;
}现在是不是要在前台写一个<html:errors>用来显示呢?
请给一个显示错误的示例好吗?谢谢。
都知道Struts中表单验证错误信息需要编辑com.工程名.struts下的ApplicationResources.properties文件,但是我不知道怎么编辑。
比如,我在登录界面的验证表单中有以下代码:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(userid==null&&userid.trim().length()<1){
errors.add("UserIDIsNull", new ActionMessage("UserIDIsNull"));
}
if(password==null&&password.trim().length()<1){
errors.add("PasswordIsNull", new ActionMessage("PasswordIsNull"));
}
return errors;
}现在是不是要在前台写一个<html:errors>用来显示呢?
请给一个显示错误的示例好吗?谢谢。
if(xxxx){
errors.add("error", new ActionError("alert_rand"));
}
return (errors);jsp用<html:errors>就可以显示.
我以前的校验就用这个,缺点就是必须在validate()里调用。
现在我改用更好的,ActionMessages errors = new ActionMessages();优点是在ActionBean里就可以用了。
if(****.equals("")){
ActionError error=new ActionError("error.eventcodeRequest");
actionErrors.add("eventcodeRequest",error);
}ApplicationResources.properties文件中写:error.eventcodeRequest=<tr><td><strong>\u653b\u51fb\u4ee3\u53f7\u662f\u5fc5\u987b\u7684</strong></td></tr>红字是编译的过来的语言,否则计算机不认识
errors.add("UserIDIsNull", new ActionMessage("UserIDIsNull"));
}
那么我在ApplicationResources.properties文件中该怎么写呢?写成UserIDIsNull=用户名为空??然后怎么将中文编译一下?