<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jstl練習</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my JSP page. <br> <h6>下面是out測試</h6> <c:out value="out"></c:out> <h6>下面是set測試</h6> <% request.setAttribute("out", "hello"); %> <c:set var="username" value="test"></c:set> <c:out value="${username }" /> <h6>下面是curl測試</h6> <a href="<c:url value='index.jsp'> <c:param name='username' value='戰三'/> </c:url>">index </a> <h6>下面是if測試</h6> <c:set var="password" value="12345"></c:set> <c:if test="${not empty password}"> <c:out value="${password}"></c:out> </c:if> <h6>下面是choose測試</h6> <c:choose> <c:when test="${not empty param.name}">測試空</c:when> <c:otherwise>不為空</c:otherwise> </c:choose> <h6>下面是foreach測試</h6> <c:forEach var="i" begin="1" end="10"> ${i} </c:forEach> <br /> <% String[] array = { "1", "2" }; request.setAttribute("array", array); %> <c:forEach items="${array}" var="item"> ${item} </c:forEach> <h6>下面是fmt測試</h6> <c:out value="記得加fmt庫"/> <% Date date=new Date(); request.setAttribute("date", date); %> 當前時間為: <fmt:formatDate value="${date}" pattern="yyyy-MM-dd hh:mm:ss"/> </body> </html>