如何使用 JSTL 标签检查资源包键是否不存在? [英] 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 标签检查资源包键是否不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文