我正在使用(学习......)Struts 1.3来构建一个MVC Web应用程序.为清楚起见,我想包含多个<message-resources>元素 - 将消息分离为应用程序特定模块的文件.
官方的Apache文档说明:
您可以
<message-resources>为您的webapp 定义一个或多个元素; 模块可以定义自己的资源包.可以在应用程序中同时使用不同的包,"key"属性用于指定所需的包.
但是,当我包含多个元素时,JSP会导致异常,指出密钥缺少消息:
SEVERE: Servlet.service() for servlet jsp threw exception javax.servlet.jsp.JspException: Missing message for key "label.username" in bundle "(default bundle)" for locale en_GB
at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:233)
at org.apache.jsp.index_jsp._jspx_meth_bean_005fmessage_005f0(index_jsp.java:197)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:107) ~~~snip~~~
Run Code Online (Sandbox Code Playgroud)
这是XML:
<struts-config>
~~~snip~~~
<message-resources parameter="resources.DefaultResource"/>
<message-resources parameter="resources.Registration"/>
</struts-config>
Run Code Online (Sandbox Code Playgroud)
如果没有第二个"注册"资源,则不会抛出异常."label.username"仅存在于"DefaultResource"中.
非常感谢.
JB *_*zet 10
使用此struts-config,第二个消息资源元素使用与第一个相同的(默认)密钥,从而完全替换第一个.您必须为每个bundle分配一个不同的键,并使用bean:message标签中的bundle atttribute来指示您要使用的bundle:
<struts-config>
~~~snip~~~
<message-resources parameter="resources.DefaultResource"/>
<message-resources parameter="resources.Registration" key="registrationBundle"/>
</struts-config>
Run Code Online (Sandbox Code Playgroud)
在JSP中:
Message from the default bundle : <bean:message key="my.first.key"/>
Message from the registration bundle : <bean:message key="my.second.key" bundle="registrationBundle"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20257 次 |
| 最近记录: |