JSP:访问 JSP EL 标签内的枚举
我的 java 枚举如下所示:
public enum EmailType { HOME, WORK, MOBILE, CUSTOMER_SERVICE, OTHER }
在 JSP 中,我试图执行如下所示的操作,但这是行不通的。
<c:choose>
<c:when test="${email.type == EmailType.HOME}">(Home)</c:when>
<c:when test="${email.type == EmailType.WORK}">(Work)</c:when>
</c:choose>
谷歌搜索后,我找到了这些链接:Enum inside a JSP。但是,我想避免在 JSP 中使用 scriplet。如何访问 EL 标签内的 java 枚举并进行比较?请帮忙。
My java enum looks like this:
public enum EmailType { HOME, WORK, MOBILE, CUSTOMER_SERVICE, OTHER }
In JSP, I am trying to do sth like below, which is not working.
<c:choose>
<c:when test="${email.type == EmailType.HOME}">(Home)</c:when>
<c:when test="${email.type == EmailType.WORK}">(Work)</c:when>
</c:choose>
After googling, I found these links: Enum inside a JSP. But, I want to avoid using scriplets in my JSP. How can I access the java enum inside EL tag and do the comparision?? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当枚举被序列化时,它就变成了字符串。所以只需使用字符串比较即可。
When an enum is serialized it becomes a string. So just use a string compare.