评估 JSTL 标记中的 Struts 值

Evaluating a Struts value within a JSTL tag

我目前正在为基于 Struts 2 构建的应用程序开发语言包。语言包在属性文件中定义,前端 JSP 将通过 JSTL (FMT) 访问该文件标签)。

我正在尝试实现类似于字符串格式化的功能,即将 Struts 值插入到通过 FMT 标记检索的句子字符串中。

我的属性文件中定义了什么:

userprofile.link.text = <a href="{0}">Click here</a> to view your profile page.

从JSP这边,

<fmt:message key="userprofile.link.text">
   <fmt:param value='/profile/<s:property value="userBean.id"/>'/>
</fmt:message>

但是,link 无法正确呈现。我该如何实现?

  1. JSTL使用${}(EL);

  2. Struts2 ValueStack 通过 StrutsRequestWrapper:

    暴露给 JSTL

    All Struts requests are wrapped with this class, which provides simple JSTL accessibility. This is because JSTL works with request attributes, so this class delegates to the value stack [...]

那么这应该足够了:

<fmt:message key="userprofile.link.text">
    <fmt:param value='/profile/${userBean.id}'/>
</fmt:message>