---
title: "（3）struts的错误提示"
author: "bolan392"
date: "2009-07-08T14:43:43Z"
tags: []
slug: "3-struts"
draft: false
lastmod: "2009-07-08T14:43:43Z"
id: 421894
url: "https://bolan392.iteye.com/blog/421894"
---

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的自定义标签显示错误信息**

    &lt;html:errors property="num"/&gt;

**4.   中文提示信息的解决：首先新建一个临时文件test.properties内容如下：**

    error.input=只能输入数字

    然后在命令行中使用jdk自带工具进行编码格式转换

    native2ascii -encoding gbk test.properties Message\_zh\_CN.properties