JSP中使用JSTL按不同條件輸出內(nèi)容的方法
更新時間:2015年10月10日 11:33:16 作者:紅薯
這篇文章主要介紹了JSP中使用JSTL按不同條件輸出內(nèi)容的方法,實例分析了JSP標簽庫JSTL的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了JSP中使用JSTL按不同條件輸出內(nèi)容的方法。分享給大家供大家參考。具體如下:
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程序設(shè)計有所幫助。
相關(guān)文章
Struts2 OGNL調(diào)用公共靜態(tài)方法詳細介紹
這篇文章主要介紹了Struts2 OGNL調(diào)用公共靜態(tài)方法詳細介紹的相關(guān)資料,需要的朋友可以參考下2017-01-01
搭建java WEB開發(fā)環(huán)境和應(yīng)用
使用Tomcat服務(wù)器,使用DBCP數(shù)據(jù)源搭建Web開發(fā)環(huán)境2009-06-06
JSP對瀏覽器發(fā)送來的數(shù)據(jù)進行重新編碼的兩種方式
使用JSP操作中文時,經(jīng)常會出現(xiàn)一些亂碼問題。這里,我們只談一下對瀏覽器發(fā)送來的數(shù)據(jù)進行重新編碼時的編碼方式。眾所周知,要對瀏覽器發(fā)送來的數(shù)據(jù)進行重新編碼,只需要一個語句就可以了,很簡單2013-09-09

