评估JSTL标记内的Struts值 [英] Evaluating a Struts value within a JSTL tag

查看:61
本文介绍了评估JSTL标记内的Struts值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently developing a language pack for an application built on Struts 2. The language pack is defined in a properties file which will be accessed by the frontend JSP via JSTL (FMT tags).

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

I'm trying to achieve something like String formatting, i.e. inserting a Struts value into a sentence string retrieved via an FMT tag.

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

What's defined in my properties file:

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>

但是,链接无法正确呈现.我该如何实现?

However, the link does not render correctly. How do I achieve this ?

推荐答案

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

Struts2 ValueStack通过 StrutsRequestWrapper :

Struts2 ValueStack is exposed to JSTL through the StrutsRequestWrapper:

所有Struts请求都被此类包装,该类提供了简单的JSTL可访问性.这是因为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>

这篇关于评估JSTL标记内的Struts值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆