jstl的几个常用c标签

本文详细介绍了JSTL(JavaServer Pages Standard Tag Library)标签库的使用方法,包括if、set、remove、choose和forEach等常用标签的功能与实例。通过本文,读者可以了解如何在JSP页面中使用JSTL简化页面逻辑处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

if 标签
<c:if test = “ u s e r i d = = 1 &quot; &gt; &lt; / c : i f &gt; s e t 标 签 在 p a g e C o n t e x t 里 添 加 变 量 &lt; c : s e t n a m e = &quot; l i &quot; v a l u e = &quot; 123 &quot; &gt; r e m o v e 标 签 删 除 s c o p e 作 用 域 中 的 值 &lt; c ; r e m o v e n a m e = &quot; l i &quot; s c o p e = &quot; p a g e &quot; &gt; c h o o s e w h e n 标 签 类 似 i f e l s e 的 用 法 &lt; c : c h o o s e &gt; &lt; c : w h e n t e s t = &quot; t r u e &quot; &gt; 1 &lt; / c : w h e n &gt; &lt; c : w h e n t e s t = &quot; f a l s e &quot; &gt; 2 &lt; / c : w h e n &gt; &lt; c : o t h e r w i s e &gt; 3 &lt; / c : o t h e r w i s e &gt; &lt; / c : c h o o s e &gt; f o r E a c h 标 签 1. 对 l i s t 进 行 遍 历 &lt; c : f o r E a c h v a r = &quot; i t e m &quot; i t e m s = &quot; {userid == 1}&quot;&gt; &lt;/c :if&gt; set 标签在pageContext里添加变量 &lt;c:set name =&quot;li&quot; value = &quot;123&quot;&gt; remove 标签 删除scope作用域中的值 &lt;c;remove name = &quot;li&quot; scope = &quot;page&quot;&gt; choose when标签 类似if else 的用法 &lt;c:choose&gt; &lt;c:when test=&quot;true&quot; &gt;1&lt;/c:when&gt; &lt;c:when test=&quot;false&quot;&gt;2&lt;/c:when&gt; &lt;c:otherwise&gt;3&lt;/c:otherwise&gt; &lt;/c:choose&gt; forEach 标签 1.对list进行遍历 &lt;c:forEach var =&quot;item&quot; items = &quot; userid==1"></c:if>setpageContext<c:setname="li"value="123">removescope<c;removename="li"scope="page">choosewhenifelse<c:choose><c:whentest="true">1</c:when><c:whentest="false">2</c:when><c:otherwise>3</c:otherwise></c:choose>forEach1.list<c:forEachvar="item"items="{publicList}”>

</c:forEach>
2.对map进行遍历
<c:forEach var = “item” items = “publicMap”>
${item.value}
</c:forEach>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值