二.JSP標(biāo)簽
作用:
1.流程判斷
2.跳轉(zhuǎn)頁(yè)面
....
分類:
1.內(nèi)置標(biāo)簽:不需要在JSP頁(yè)面導(dǎo)入標(biāo)簽
2.jstl標(biāo)簽:需要在JSP頁(yè)面中導(dǎo)入標(biāo)簽
3.自定義標(biāo)簽:開發(fā)者自定義,需要在JSP頁(yè)面導(dǎo)入標(biāo)簽
動(dòng)態(tài)標(biāo)簽:
1.轉(zhuǎn)發(fā)標(biāo)簽:<jsp:forWard/>
2.參數(shù)標(biāo)簽:<jsp:pararm/>
3.包含標(biāo)簽:<jsp:include/>
1.內(nèi)置標(biāo)簽
- 轉(zhuǎn)發(fā)標(biāo)簽<jsp:forWard/>
index.jsp主要代碼
<jsp:forward page="index2.jsp">
<jsp:param name="mahan" value="huan"></jsp:param>
</jsp:forward>
index2.jsp
<%--
Created by IntelliJ IDEA.
User: pc
Date: 17-4-14
Time: 下午4:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%=request.getParameter("mahan")%>
</body>
</html>

- 包含標(biāo)簽<jsp:include/>
index.jsp主要代碼
<jsp:include page="head.jsp"></jsp:include>
上面是頭部
head.jsp代碼
<%--
Created by IntelliJ IDEA.
User: pc
Date: 17-4-14
Time: 下午4:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>我是頭部</h1>
</body>
</html>

2.jstl標(biāo)簽
全名(java standard tag libarary) java標(biāo)準(zhǔn)標(biāo)簽庫(kù)
1.核心標(biāo)簽庫(kù)(C標(biāo)簽庫(kù))--重點(diǎn)
2.國(guó)際哈化標(biāo)簽庫(kù)(fmt標(biāo)簽庫(kù))
3.EL函數(shù)庫(kù)(fn函數(shù)庫(kù))
4.XML標(biāo)簽庫(kù)(x標(biāo)簽庫(kù))--次要
5.sql標(biāo)簽庫(kù)(sql標(biāo)簽庫(kù))--次要
- 核心標(biāo)簽庫(kù)
保存數(shù)據(jù):
<c:set></c:set>
獲取數(shù)據(jù):
<c:out value=""></c:out>
單條件判斷:
<c:if test=""></c:if>
<多條件判斷>
<c:choose></c:choose>
<c:when test=""></c:when>
<c:otherwise></c:otherwise>
循環(huán)數(shù)據(jù):
<c:forEach></c:forEach>
<c:forTokens items="" delims="">
</c:forTokens>
重定向 :
<c:redirect></c:redirect>
1)導(dǎo)入jstl支持的jar包:下載地址 密碼: g853
2)導(dǎo)入標(biāo)簽庫(kù)
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3)標(biāo)簽
a.保存數(shù)據(jù):<c:set></c:set>.
默認(rèn)將數(shù)值存入page域中
<c:set var="mahuan" value="huanhuan"></c:set>
${mahuan}
scope="域?qū)ο?(page,request,session,application)
<c:set var="mahuan" value="huanhuan" scope="request"></c:set>
${requestScope.mahuan}
b.獲取數(shù)據(jù):<c:out value=""></c:out>
從域中獲取數(shù)值
<c:set var="mahuan" value="huanhuan" scope="request"></c:set>
<c:out value="${mahuan}"></c:out>
default="默認(rèn)值" 當(dāng)值為null時(shí)顯示默認(rèn)值
escapeXml=" "(true false)是否對(duì)value的值進(jìn)行轉(zhuǎn)義默認(rèn)轉(zhuǎn)義(true)
<%
String str =null;
pageContext.setAttribute("aaa",str);
%>
<c:out value="${aaa}" default="<h2>默認(rèn)值</h2>" escapeXml="false"></c:out>

c.單條件判斷:<c:if test=""></c:if>
test=" "(true false)判斷是否要輸出
<c:if test="true">
判斷輸出
</c:if>
<c:if test="${30>22}">
判斷輸出
</c:if>
d.<多條件判斷>
<c:choose></c:choose>
<c:when test=""></c:when>
<c:otherwise></c:otherwise>
<c:set var="mahuan" value="78" ></c:set>
<c:choose>
<c:when test="${mahuan>90 && mahuan<=100}">
特等獎(jiǎng)
</c:when>
<c:when test="${mahuan>80 && mahuan<=90}">
一等獎(jiǎng)
</c:when>
<c:when test="${mahuan>70 && mahuan<=80}">
二等獎(jiǎng)
</c:when>
<c:when test="${mahuan>60 && mahuan<=70}">
三等獎(jiǎng)
</c:when>
<c:otherwise>
參賽獎(jiǎng)
</c:otherwise>
</c:choose>

e.循環(huán)數(shù)據(jù):<c:forEach></c:forEach>
begin= " " 從那個(gè)元素開始遍歷,默認(rèn)從0開始
end=" " 到那個(gè)數(shù)據(jù)結(jié)束,默認(rèn)到最后一個(gè)結(jié)束
step=“ ” 步長(zhǎng) 默認(rèn)為1
items=“ ” 需要遍歷的數(shù)據(jù)集合
var=“ ” 每個(gè)元素的名稱
varStatus= “ ” 當(dāng)前正在遍歷元素的狀態(tài)對(duì)象(count屬性:當(dāng)前位置,從1開始)--序列
list集合:
<%
List<Student> list= new ArrayList<Student>();
list.add(new Student("張三","21"));
list.add(new Student("小明","32"));
list.add(new Student("小花","44"));
pageContext.setAttribute("list",list);
%>
<c:forEach begin="0" end="2" items="${list}" step="1" var="Student" varStatus="varsta">
序號(hào):${varsta.count} 姓名: ${Student.name} 年齡:${Student.age}<br>
</c:forEach>

map集合:
<%
Map<String ,Student> map = new HashMap<String,Student>();
map.put("011",new Student("張飛","44"));
map.put("012",new Student("小花","47"));
map.put("013",new Student("小明","52"));
pageContext.setAttribute("map",map);
%>
<c:forEach begin="0" end="2" items="${map}" step="1" var="Student" varStatus="varsta">
序號(hào):${varsta.count} 編號(hào)${Student.key} 姓名: ${Student.value.name} 年齡:${Student.value.age}<br>
</c:forEach>

f.<c:forTokens items="" delims=""> </c:forTokens>
循環(huán)特殊字符串
<%
String sr = "ma-huan-huan-ni-hao";
pageContext.setAttribute("huan",sr);
%>
<c:forTokens items="${huan}" delims="-" var="s">
${s}<br>
</c:forTokens>

g.<c:redirect></c:redirect>
重定向
<c:redirect url="http://www.itdecent.cn/u/ac5fd281184c"></c:redirect>
-
完
文集:JavaEE--學(xué)習(xí)筆記