本文实例讲述了jsp中使用jstl按不同条件输出内容的方法。分享给大家供大家参考。具体如下:
conditionalcontentjstl.jsp页面:
<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<%@ taglib uri="/web-inf/tld/c-rt.tld" prefix="c-rt" %>
<html>
<head>
<title>java code geeks snippets - conditional content with jstl in jsp page</title>
</head>
<body>
<%-- if condition --%>
<c-rt:if test='${param.myparam1 == "myvalue1"}'>
this is printed if parameter "myparam1" equals "myvalue1" </br>
</c-rt:if>
<%-- if/else condition --%>
<c-rt:choose>
<c-rt:when test='${param.myparam2 == "myvalue2"}'>
this is printed if parameter "myparam2" equals "myvalue2" </br>
</c-rt:when>
<c-rt:otherwise>
this is printed if parameter "myparam2" does not equal "myvalue2" </br>
</c-rt:otherwise>
</c-rt:choose>
<%-- multiple conditions --%>
<c-rt:choose>
<c-rt:when test='${param.myparam3 == "0"}'>
this is printed if parameter "myparam1" equals 0 </br>
</c-rt:when>
<c-rt:when test='${param.myparam3 == "1"}'>
this is printed if parameter "myparam1" equals 1 </br>
</c-rt:when>
<c-rt:otherwise>
this is printed for any other value of the parameter </br>
</c-rt:otherwise>
</c-rt:choose>
</body>
希望本文所述对大家的jsp程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!