if...else 在 JSP 或 JSTL 中 [英] if...else within JSP or JSTL

查看:33
本文介绍了if...else 在 JSP 或 JSTL 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据 JSP 文件中的某些条件输出一些 HTML 代码.

if(条件 1){一些特定于条件 1 的 HTML 代码}否则如果(条件2){一些特定于条件 2 的 HTML 代码}

我该怎么做?我应该使用 JSTL 吗?

解决方案

<块引用>

我应该使用 JSTL 吗?

是的.

您可以使用 标签在使用 JSTL 的 jsp 中进行条件渲染.

要模拟 if ,您可以使用:

<c:if test="condition"></c:if>

要模拟if...else,您可以使用:

<c:when test="${param.enter=='1'}">比萨.<br/></c:when><c:否则>比萨饼.<br/></c:否则></c:选择>

I want to output some HTML code based on some condition in a JSP file.

if (condition 1) {
    Some HTML code specific for condition 1
}
else if (condition 2) {
    Some HTML code specific for condition 2
}

How can I do that? Should I use JSTL?

解决方案

Should I use JSTL ?

Yes.

You can use <c:if> and <c:choose> tags to make conditional rendering in jsp using JSTL.

To simulate if , you can use:

<c:if test="condition"></c:if>

To simulate if...else, you can use:

<c:choose>
    <c:when test="${param.enter=='1'}">
        pizza. 
        <br />
    </c:when>    
    <c:otherwise>
        pizzas. 
        <br />
    </c:otherwise>
</c:choose>

这篇关于if...else 在 JSP 或 JSTL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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