请注意,param-name 应用程序和值表示为beatest.ApplicationResources。这表示在应用程序类路径的包 beatest 内一定存在一个名为 ApplicationResources.properties 的属性文件。
在 Struts 1.1 中,可以在 struts-config.xml 中定义资源包。
<message-resources parameter="beatest.ApplicationResources"/>
此处的参数为必需值,它引用类路径 beatest 包中的 ApplicationResources.properties 文件。使用 Struts 1.1 时可以有多个资源包,这使开发人员还能够对资源包进行组织。例如,可以有这样的包:
<message-resources key=”errorBundle” parameter="beatest.ApplicationErrors"/>
和
<message-resources key=”labelsBundle” parameter="beatest.ApplicationLabels"/>
可以在应用程序中对它们进行适当设置。如果用户想要为 HTML 显示标签,则可以使用 labelsBundle。
<bean:message bundle="lablesBundle" key="some.message.key"/>
而如果想要显示错误信息,则可以使用 errorBundle。
<bean:message bundle="errorBundle" key="some.error.message"/>
返回页首
使用消息资源时的常见问题 开发 Struts 应用程序过程中的一个常见错误是:
javax.servlet.jsp.JspException:Missing message for key "<some key name>"
要解决此问题,可以确认是否存在下列情况:
-
消息不是从正确的资源包取得的。请确保引用的是真正包含所提及的键的正确的资源包。
-
资源属性文件不在正确的位置或不在应用程序的类路径中。应用程序资源属性文件应位于 WEB-INF\classes 目录中,或应为 WEB-INF\lib 目录中某个 .jar 文件的一部分。
-
使用 null="false" 可避免上述错误。例如:
<bean:message bundle="lablesBundle" key="some.message.key" null="false">
这样将会设置一个消息资源包,在文件 MyWebAppResources.properties 的缺省键下提供该资源包。缺少的资源键将显示为“???keyname???”。
返回页首
|