How can I check if a resource bundle key does not exist using JSTL tags?(如何使用 JSTL 标签检查资源包键是否不存在?)
问题描述
我有一个包含一些可选键的资源文件.如果可选资源键不存在,我设置一个默认值.似乎没有简单的方法来确定资源包中是否存在密钥.所以这就是我正在做的解决它.
I have a resource file that will have some optional keys. If the optional resource key is not present, I set a default instead. It appears that there is no easy way to determine if a key exists in the resource bundle. So this is what I'm doing to get around it.
<fmt:message var="title" key="login.reg.signup.${signupForm.regfrom}.title" />
<c:if test='${fn:startsWith(title, "??")}'>
<fmt:message var="title" key="login.reg.signup.default.title" />
</c:if>
有没有更好的办法?
推荐答案
您可以编写自己的 JSP 标签来执行此操作,然后您就可以这样做:
You could write your own JSP tag that does this, so you can then just do:
<my:message var="title" key="${form}.title" default="default.title"/>
标签实现可以是您当前的 JSP 语法,也可以是 Java 类.
The tag implementation could either be your current JSP syntax, or a Java class.
这篇关于如何使用 JSTL 标签检查资源包键是否不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 JSTL 标签检查资源包键是否不存在?
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
