gpt4 book ai didi

java - 如何比较 JSTL 1.0 中 bean 属性的子字符串?

转载 作者:行者123 更新时间:2023-12-02 08:37:32 27 4
gpt4 key购买 nike

我在 jsp 页面中有以下代码(Struts 支持):

<c:if test="${USERINFO.someproperty == 'test'}">
...
</c:if>

但是我想做的是仅比较某些属性的子字符串,例如如果后缀以“st”结尾。我使用的是 JSTL 1.0,因此 JSTL 1.1 中的endsWith() 函数不可用(据我所知),此外,我更喜欢一个不需要我为此编写自定义 Java 类的解决方案。

我在想一些事情:

<c:set var="someproperty"><%= USERINFO.someproperty.substring(USERINFO.someproperty.length()-2, 2) %></c:set>
<c:if test="${someproperty == 'st'}">
...
</c:if>

但是 USERINFO 当然不能像那样被 Java 访问。

有什么想法吗?

最佳答案

或者如果您想避免 scriptlet,则只需使用字符串标记库: http://jakarta.apache.org/taglibs/doc/string-doc/intro.html

<c:set var="someproperty">
<str:substring start="${USERINFO.someproperty.length-2}" end="2">The tree is green.</str:substring>
</c:set>

<c:if test="${someproperty == 'st'}">
...
</c:if>

关于java - 如何比较 JSTL 1.0 中 bean 属性的子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1091249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com