如何使用JSTL执行等效的java If-Else块? [英] How do I do the equivalent of a java If-Else block using JSTL?

查看:90
本文介绍了如何使用JSTL执行等效的java If-Else块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速的JSTL问题。我通常在我的jsp页面中使用scriptlet,但由于我的页面中的其他一些内容而产生冲突。我知道你可以使用JSTL做这样的事情,虽然我不熟悉它。以下是我将使用java编写的代码:

A quick JSTL question. I usually use scriptlets in my jsp pages, but have a conflict due to some other things in my page. I understand you can do something like this using JSTL, although I am not familiar with it. Here is what I would code using java for this:

if (var1.equalsIgnoreCase(var2)) { 

some html stuff

} else {

more html

}

那么这可以转换并转换为与JSTL一起使用吗?

So can this be converted and translated to be used with JSTL?

提前致谢,如果您有任何疑问,请告诉我。

Thanks in advance and if you have any questions, just let me know.

推荐答案

您可以使用 < c:选择> equalsIgnoreCase()可以通过 fn:toLowerCase()

You can use <c:choose> for this. The equalsIgnoreCase() can be done by lowercasing the both sides by fn:toLowerCase().

<c:choose>
    <c:when test="${fn:toLowerCase(var1) == fn:toLowerCase(var2)}">
        Both are equal.
    </c:when>
    <c:otherwise>
        Both are not equal.
    </c:otherwise>
</c:choose>

或者当你的目标是Servlet 3.0容器时(Tomcat 7,Glassfish 3,JBoss AS 6,等)使用 web.xml 声明符合Servlet 3.0,然后你可以调用 equalsIgnoreCase()方法。

Or when you're targeting a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss AS 6, etc) with a web.xml declared conform Servlet 3.0, then you can invoke the equalsIgnoreCase() method.

<c:choose>
    <c:when test="${var1.equalsIgnoreCase(var2)}">
        Both are equal.
    </c:when>
    <c:otherwise>
        Both are not equal.
    </c:otherwise>
</c:choose>

这篇关于如何使用JSTL执行等效的java If-Else块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆