1. 在资源配置文件中添加错误信息键值对
error=InputError
2. 在Action中,如果出现错误,则按照以下方式存储错误信息
ActionMessages errors = new ActionMessages();
try{
r = c.add(Double.parseDouble(f.getFirst()),Double.parseDouble(f.getSecond()));
}catch(Exception e){
errors.add("num",new ActionMessage("error"));
this.saveErrors(request, errors);
return mapping.findForward("input");
}
3. 页面中使用struts的自定义标签显示错误信息
<html:errors property="num"/>
4. 中文提示信息的解决:首先新建一个临时文件test.properties内容如下:
error.input=只能输入数字
然后在命令行中使用jdk自带工具进行编码格式转换
native2ascii -encoding gbk test.properties Message_zh_CN.properties