header.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
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" %>
<!-- 함수태그 -->
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="path" value="${pageContext.request.contextPath }" />
ex04.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<h2>JSTL 반복문</h2>
<!--
varStatus 상태변수
varStatus.index 0부터 시작하는 일련번호
varStatus.count 1부터 시작하는 일련번호
-->
<%--
<c:forEach var="i" begin="1" end="100" step="2" varStatus="num">
${num.index } ${num.count }<span style="font-size:${100-i}px">hello</span><br>
</c:forEach>
--%>
<br>
<%-- <c:forEach var="i" begin="2" end="9">
<h2>${i}단</h2>
<c:forEach var="j" begin="1" end="9">
${i} * ${j} = ${i*j} <br>
</c:forEach>
</c:forEach>
--%>
<c:forEach var="i" begin="${param.start}" end="${param.end}">
<h2>${i}단</h2>
<c:forEach var="j" begin="1" end="9">
${i} * ${j} = ${i*j} <br>
</c:forEach>
</c:forEach>
</body>
</html>
JSTL 반복문0단0 * 1 = 0
|
ex05.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<!-- ex04.jsp로 redirect -->
<!-- response.sendRedirect("ex04.jsp?start=2&end=9") -->
<c:redirect url="ex04.jsp">
<c:param name="start" value="7"></c:param>
<c:param name="end" value="9"></c:param>
</c:redirect>
</body>
</html>
JSTL 반복문7단7 * 1 = 77 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 7 * 8 = 56 7 * 9 = 63 8단8 * 1 = 88 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 8 * 9 = 72 9단9 * 1 = 9
|
ex06.jsp
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="header.jsp" %>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<%
Date date1 =new Date();
out.println(date1 + "<br>");
%>
<c:set var="date" value="<%= new Date() %>" />
${date } <br/>
<fmt:formatDate value="${date}"/> <br>
( type="date" ): <fmt:formatDate value="${date}" type="date" /><br>
( type="time" ): <fmt:formatDate value="${date}" type="time" /><br>
( pattern="yyyy-MM-dd HH:mm:ss" ): <fmt:formatDate value="${date}" pattern="yyyy-MM-dd HH:mm:ss" /><br>
( dateStyle="full"): <fmt:formatDate value="${date}" dateStyle="full" /><br>
( dateStyle="long" ): <fmt:formatDate value="${date}" dateStyle="long" /><br>
( dateStyle="medium" ): <fmt:formatDate value="${date}" dateStyle="medium" /><br>
( dateStyle="short" ): <fmt:formatDate value="${date}" dateStyle="short" /><br>
<c:set var="num" value="123456789.12" />
${num}<br>
천단위 컴머 :
<fmt:formatNumber value="${num}" groupingUsed="true" />
<p>
패턴 사용:
<fmt:formatNumber value="${num}" pattern="#,####.###" />
<p>
소수 빈자리를 0으로 채움 :
<fmt:formatNumber value="${num}" pattern="#,####.000"/>
</body>
</html>
Thu May 25 13:16:20 KST 2017 패턴 사용: 1,2345,6789.12 소수 빈자리를 0으로 채움 : 1,2345,6789.120
|
ex07.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="header.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<c:set var="str" value="hello jsp" />
문자열의 길이 : ${fn:length(str)}<br>
키워드의 인덱스 : ${fn:indexOf(str, 'jsp')}<br>
문자열 변경 : ${fn:replace(str, 'jsp', 'java') }<br>
</body>
</html>
문자열의 길이 : 9
|
댓글 ( 4)
댓글 남기기