如何使用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屋!
查看全文