简体   繁体   English

从Struts 2中的资源包加载消息

[英]Loading messages from resource bundle in Struts 2

I want to load resource bundle (I have two: one for selected language and another default) dynamically in JSP and read the content in JSP. 我想在JSP中动态加载资源包(我有两个:一个用于选择的语言,另一个用于默认),并在JSP中读取内容。 I have tried following way but its just hard-coded. 我尝试了以下方式,但它只是硬编码。

<s:i18n name="resourcebundle_fr">
   <s:text name="fr_message1" />
</s:i18n>

where what I want is instead of resourcebundle_fr , I want it to be dynamic. 我想要的是不是resourcebundle_fr ,我希望它是动态的。 Also, the same page has included another JSP page which should also pick the messages from the selected language specific resource bundle. 同样,同一页面还包括另一个JSP页面,该页面也应从所选语言特定的资源包中选择消息。

Struts2 tags has support for OGNL. Struts2标签支持OGNL。 You can use OGNL expressions in the Struts tag's attributes. 您可以在Struts标记的属性中使用OGNL表达式。

<s:i18n name="%{resourceBundle}">
  <s:text name="fr_message1" />
</s:i18n>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM