可以在JSP中排序吗?

发布于 2024-10-05 21:33:53 字数 445 浏览 0 评论 0原文

有没有办法按字母顺序对 JSP 中的两个字符串变量进行排序,例如使用 jstl?或者至少确定哪个字符串按字母顺序排在第一位?

我一直在尝试使用这样的代码。它似乎适用于一些简单的示例,但我不确定它是否考虑按字母顺序排列。当变量不是数字时,任何人都可以确认“gt”运算符是否按字母顺序排列?

<c:set value="abc" var="var1"/>
<c:set value="def" var="var2"/>
<c:if test="${var2 gt var1}">
    <p>var1 is first</p>
</c:if>
<c:if test="${var1 gt var2}">
    <p>var2 is first</p>
</c:if>

谢谢

Is there any way to sort alphabetically two strings variables in a JSP, for example by using jstl? Or at least determinate which string would be first alphabetically?

I have been trying with a code like this one. It seems to work with some simple examples, but I'm not sure that it is considering alphabetical order. Can anyone confirm whether "gt" operator takes alphabetical order when the variable is not a number?

<c:set value="abc" var="var1"/>
<c:set value="def" var="var2"/>
<c:if test="${var2 gt var1}">
    <p>var1 is first</p>
</c:if>
<c:if test="${var1 gt var2}">
    <p>var2 is first</p>
</c:if>

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2024-10-12 21:33:53

关于关于在字符串上执行 EL 运算符的问题部分,示例位于 http://java.sun.com/products/jsp/syntax/2.0/syntaxref207.html 和一些实际测试证实 gt 在字符串上按字母顺序优先。

在你的例子中 def > abc 为真,因为 d >一个

Regarding the part of your question about doing the EL operators on Strings, the example at http://java.sun.com/products/jsp/syntax/2.0/syntaxref207.html and some practical tests confirm that gt takes alphabetical precedence on Strings.

In your example def > abc will be true, since d > a

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文