본문 바로가기

JAVA/JSP & Servlet

JSP 기본 실습 : 지시자(directive) -page , include-

1. page 지시자 [import 애트리뷰트]

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import="java.util.GregorianCalendar" %>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSP : page 지시자 [import 애트리뷰트]</title>

</head>

<body>

<h1>날짜와 시각</h1>

<%

        GregorianCalendar now = new GregorianCalendar();

        String date = String.format("%TF", now);

        String time = String.format("%TT", now);

%>

오늘의 날짜 : <%= date %><br>

현재의 시각 : <%= time %><br>

 

 

</body>

</html>

 

 

 

 

 

 

 

 

 

 


 

2. include 지시자

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSP : include 지시자</title>

</head>

<body>

 

<h3>오늘의 메뉴</h3>

- 삼계탕<br />

- 닭도리탕<br />

- 해물우동<br />

<br />

 

<%@ include file="include_ex.jsp" %>

 

</body>

</html>

 

 

 

include.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import="java.util.GregorianCalendar"%>

<%

        GregorianCalendar now = new GregorianCalendar();

        out.println(String.format("%TY %Tm %Td", now, now, now));

%>