[JSP] 3주차 연습문제
3장 연습문제
08. page 디렉티브 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확 인하시오.
1
2
3
4
1. 조건 page.jsp 파일을 생성한다.
• page 디렉티브 태그에 java.util.Dale, java.lang.Math 클래스를 이용하여 현재 날짜와 5의제곱을출력한다.
2. 웹 브라우저에 'http://localhost:8080/Exercise/ch03/page.jsp'를입력하여 실 행 결과를 확인한다.
1
2
3
4
5
6
7
8
9
10
11
<html>
<head>
<%@ page import = "java.util.Date" import = "java.lang.Math" %>
<%@ page contentType = "text/html; charset=utf-8" %>
<title>page-ch03-08</title>
</head>
<body>
<p>현재 날짜 : <% out.print(new Date().toString()); %></p>
<p>5의 제곱 : <% out.print(Math.pow(5.0,2.0)); %></p>
</body>
</html>
09. include 디렉티브 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.
1
2
3
4
5
6
7
8
1.조건 header.jsp 파일을 생성한다.
• 〈h4〉태그를 이용하여 ‘Hello. Java Server Pages.‘를 선언한다.
2.include.jsp 파일을 생성한다.
• include 디렉티브 태그를 이용하여 외부 파일 header.jsp의 내용을 포함한다.
• java.util.Calendar 클래스를 이용하여 현재 시간을 출력한다.
3.웹 브라우저에 'http://localhost:8080/Exercise/ch03/include.jsp'를 입력하여 실행 결과를 확인한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>include.jsp</title>
<%@ page import = "java.util.Calendar" %>
</head>
<body>
<%@ include file = "./header.jsp" %>
<p>현재시간 : <%= Calendar.getInstance().getTime().toString() %></p>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>header.jsp</title>
</head>
<body>
<h4>Hello, Java Server Pages.</h4>
</body>
</html>
10. taglib 디렉티브 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확 인하시오.
1
2
3
4
5
1.조건 /WEB-INF/lib/ 폴더에 JSTL 태그 라이브러리인 JSTL-1.2.jar 파일을 추가한다.
2.taglib.jsp 파일을 생성한다. taglib 디렉티브 태그에 JSTL의 Core 태그를 설정하여 0부터 10까지의 짝수를 출력한다.
3. 웹 브라우저에 'http://localhost:8080/Exercise/ch03/taglib.jsp'를 입력하여 실행 결과를 확인한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="EUC-KR">
<title>taglib.jsp</title>
</head>
<body>
<c:forEach var = "n" begin = "0" end = "10" step = "2">
<c:out value = "${n}"/>
</c:forEach>
</body>
</html>
This post is licensed under CC BY 4.0 by the author.