c标签汇总

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix ="c"  %>

输出:<c:out value="恭喜发财"></c:out>
设置:<c:set  var="name"   value="韦小宝"   scope="page| request| session| application"></c:set>
      <c:set  target="${map}"  property="cellphone"  value="10010"></c:set>
删除:<c:remove  var="name"   scope="pageContext"/>
捕获异常:
<c:catch  var="e">
	<%
		int i = 1/0;
	%>
</c:catch>

多重选择:
<c:choose>
	<c:when  test="${day==1}">
		星期一
	</c:when>
	<c:when  test="${day==2}">
		星期二
	</c:when>
	<c:when  test="${day==3}">
		星期三
	</c:when>
	<c:otherwise>
		休息日
	</c:otherwise>
</c:choose>

遍历:
<%
	String[]  city = {"北京","上海","广州","铁岭"};
	pageContext.setAttribute("city",city);
%>
<c:forEach  items = "${city}"   var = "c">	//表示遍历 city 数组,每一项的值用“c”对象保存
	${c  }<br/>	//结果:北京  上海  广州  铁岭
</c:forEach>


<%
        List list = new ArrayList();
        list.add("美国");
        list.add("中国");
        list.add("俄罗斯");
        list.add("印度");
        pageContext.setAttribute("list", list);
%>
<c:forEach  items = "${list}"   var = "c">    //表示遍历 list 集合,每一项的值用“c”对象保存
       ${c  }<br/>    //结果:美国  中国  俄罗斯  印度
</c:forEach>



                <h1>遍历map</h1>
                <%
                    Map map = new HashMap();
                    map.put("name","曹操");
                    map.put("age","59");
                    map.put("wife","小乔");
                    map.put("gender","男");
                    pageContext.setAttribute("map", map);
                %>
                <c:forEach  items = "${map}"   var = "entry">    //表示遍历 city 数组,每一项的值用“c”对象保存
                    ${ entry.key }:${ entry.value }<br/>    //结果:wife:小乔  name:曹操  age:59  gender:男
                </c:forEach>


                <h1>遍历10到100的偶数,如果数字所在位置是3的倍数,显示成红色</h1>
                //varStatus    用来保存遍历状态的
                //index        索引
                //count        计数值,表示第几个位置的数字

                <c:forEach  begin = "10"   end = "100"  step="2"  var="i"   varStatus="stat">    //从0开始,到10结束,步长为2,变量名为i
                    <c:if  test="${stat.count % 3 ==0}">
                        <font color="red">
                            ${ i }
                        </font>    //结果:0,2,4,6,8,10
                    </c:if>
                    <c:if  test="${stat.count % 3 !=0}">
                        <font color="blue">
                            ${ i }
                        </font>    //结果:0,2,4,6,8,10
                    </c:if>
                </c:forEach>

转发:
                <c:redirect  url="/index.jsp"  context="${pageContext.request.contextPath}">    //context 中写跳转的web应用名称,url表示跳转到哪个页面
                    <c:param  name="name"  value="zhang"/>
                </c:redirect>

获取url地址:<c:url  value="/index.jsp"  context="${pageContext.request.contextPath}"  var="url"  scope="page">

重定向:<c:redirect  url="/index.jsp"  context="${pageContext.request.contextPath}">    //context 中写跳转的web应用名称,url表示跳转到哪个页面

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值