核心标签库<c:set>标签、<c:choose>标签、<c:forEach>标签&<c:if>标签的使用例子

<c:set>标签

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>

    <c:set var="info1" value="www.gis520.com" scope="request"/>
    <c:set var="info2" scope="request">
    	 www.gisren.com 
    	</c:set>
    <h3><c:out value="info1--->${requestScope.info1}"/></h3>
    	  <h3><c:out value="info2--->${requestScope.info2}"/></h3>
    	  	  <h3><c:out value="${pageScope.info1}" default="page属性范围没有内容哦!"/></h3>
  </body>
</html>

<c:choose>标签


<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>
  <c:choose >
  	 <c:when test="${2>3}">
  	 	 <h3>when 2<3</h3>
  	 	</c:when>
  	 	<c:otherwise>
  	 		<h3>2大于3</h3>
  	 		
  	 		</c:otherwise>
  	
  	</c:choose>
   	
  </body>
</html>

<c:forEach>标签

(1)输出数组:

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>
  	<%
  	 String info[]={"www.gisren.com","www.gis520.com","www.3sera.com"};
  	 pageContext.setAttribute("ref",info);
  	%>
  输出全部内容:
  <c:forEach items="${ref}" var="mem">
  	${mem}、
  </c:forEach>
  <br> 间隔为2:
   <c:forEach items="${ref}" var="mem" step="2">
   	${mem}、
   	</c:forEach>
   <br>输出前两个:
   <c:forEach items="${ref}" var="mem" begin="0" end="1">
   	${mem}、
   	</c:forEach>
  </body>
</html>

(2)输出list

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>
  	<%
  	 List all=new ArrayList();
  	 all.add("www.3sera.com");
  	 all.add("www.gisren.com");
  	 all.add("www.gis520.com");
  	 pageContext.setAttribute("ref",all);
  	%>
  输出list全部内容:
  <c:forEach items="${ref}" var="mem">
  	${mem}、
  </c:forEach>
  <br> 间隔为2:
   <c:forEach items="${ref}" var="mem" step="2">
   	${mem}、
   	</c:forEach>
   <br>输出list前两个:
   <c:forEach items="${ref}" var="mem" begin="0" end="1">
   	${mem}、
   	</c:forEach>
  </body>
</html>

(3)输出map

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>
  	<%
  	 Map map=new HashMap();
  	 map.put("3sera","www.3sera.com");
  	 map.put("gisren","www.gisren.com");
  	 map.put("gis520","www.gis520.com");
  	 pageContext.setAttribute("ref",map);
  	%>
  输出map全部内容:
  <c:forEach items="${ref}" var="mem">
  	<h2>${mem.key}-->${mem.value}、</h2>
  </c:forEach>
  <br> 间隔为2:
   <c:forEach items="${ref}" var="mem" step="2">
   ${mem.key}-->${mem.value}、
   	</c:forEach>
   <br>输出list前两个:
   <c:forEach items="${ref}" var="mem" begin="0" end="1">
   	${mem.key}-->${mem.value}、
   	</c:forEach>
  </body>
</html>

<c:if>标签

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="c" uri="jst/core"%>
<html>
  <head><title>核心标签库</title></head>	
  <body>
  <c:if test="${10>=20}" var="result1" scope="request"/>
    <h3>result1:${result1}</h3>
   <c:if test="${10<20}" var="result2" scope="request">
   	<%
   	String info="www.gisren.com";
   	request.setAttribute("info",info);
   	%>
   	</c:if>
   	<h3>info:${info}</h3>
  </body>
</html>


将每个demo的相应的标签引用为

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

上面的路径:

uri="jst/core"
是个人配置的,故统一变为这个即可!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值