<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"
是个人配置的,故统一变为这个即可!