JSTL(C標籤)
阿新 • • 發佈:2018-12-13
c:out
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 引入jsp標籤庫 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
pageContext.setAttribute("people", "小二");
%>
<c:out value="jstl大爺你好"></c:out>
<h2><c:out value="${people}" ></c:out></h2>
</body>
</html>
c:catch
c:choose
c:forEach
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="po.*"%>
<%@ page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String dogs[]={"小黑","小黃","小白","小小"};
pageContext.setAttribute("dogs",dogs);
%>
<c:forEach var="e" items="${dogs }"><!-- 下標從0開始 -->
${e }
</c:forEach>
<hr/>
<c:forEach var="e" items="${dogs }" step="2"><!-- 步進2 小黑小白-->
${e }
</c:forEach>
<hr/>
<c:forEach var="e" items="${dogs }" begin="1" end="2"><!--小黃小白-->
${e }
</c:forEach>
<hr/>
<%
List<People> pList=new ArrayList<People>();
pList.add(new People(1,"張三",10));
pList.add(new People(2,"李四",20));
pList.add(new People(3,"王五",30));
pageContext.setAttribute("pList",pList);
%>
<table>
<tr>
<th>編號</th>
<th>姓名</th>
<th>年齡</th>
</tr>
<c:forEach var="p" items="${pList }">
<tr>
<td>${p.id }</td>
<td>${p.name }</td>
<td>${p.age }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
c:forTokens
c:if
c:impport
c:url
c:redirect
target.jsp
c:set
c:remove