Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to output some HTML code based on some condition in a JSP file. (我想根据某些条件在JSP文件中输出一些HTML代码。)

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? (我应该使用JSTL吗?)

  ask by testndtv translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
387 views
Welcome To Ask or Share your Answers For Others

1 Answer

Should I use JSTL ? (我应该使用JSTL吗?)

Yes. (是。)

You can use <c:if> and <c:choose> tags to make conditional rendering in jsp using JSTL. (您可以使用<c:if><c:choose>标签使用JSTL在jsp中进行条件渲染。)

To simulate if , you can use: (要模拟if ,可以使用:)

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

To simulate if...else , you can use: (要模拟if ... else ,可以使用:)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...