java - bean :message in Struts 1. 3 中的动态键

标签 java jsp struts-1

我正在从事一个项目,该项目使用了一个旧的(但很好的)框架 Struts 1.3,我正在尝试完成一个简单的任务。

我有一个包含属性的bean,它是对应于属性文件的键。我想用它来记忆适当的翻译。

属性文件中的变量

props.myprop.sample=This is my sample property

该属性位于传递给 jsp 的 bean 中,为方便起见调用了 AllProps,它具有该属性的 getter,这应该是一个伪代码:

<bean:define id="sample" name="AllProps" property="sample" type="java.lang.String"/> // should result in sample = props.myprop.sample

<div><bean:message key="sample"/></div>

应该输出:

<div>This is my sample property</div>

但很明显导致找不到属性,你能帮我看看如何处理吗? 我想尽可能坚持 Struts 标签,然后是 Jsp 标签,最后是 scriptlet。

谢谢

最佳答案

直接来自 the documentation :

<bean:message>

Render an internationalized message string to the response.

Retrieves an internationalized message for the specified locale, using the specified message key, and write it to the output stream. Up to five parametric replacements (such as "{0}") may be specified.

The message key may be specified directly, using the key attribute, or indirectly, using the name and property attributes to obtain it from a bean.

(强调我的)

所以,你只需要

<bean:message name="AllProps" property="sample"/>

关于java - bean :message in Struts 1. 3 中的动态键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10451218/

相关文章:

java - 如何在 struts 文本字段标签中放置占位符?

java - 迁移到 Tomcat7 后,BeanUtils.populate 在 struts 中抛出 NullPointerException

java - 如何从一个 servlet 文件调用另一个 servlet 文件?

java - 我应该如何使用 servlet 和 Ajax?

javascript - 如果 struts/自定义标签位于 javascript 方法内,它们何时得到解析

spring - 如何为 Spring MVC 添加简单的分页

java - JSP AJAX文件上传

java - 如何使用 Maven 将 .jar 文件部署到 JBoss EAP6 服务器?

java - 接受不同类型的 JSON 数组输入?

java - 在 Android Studio 3 中设置 JNI