| 스크립트 태그 | 형식 | 설명 |
|---|---|---|
| 선언문(declaration) | <%! … %> | 자바 변수나 메소드를 정의하는 데 사용 |
| 스크립틀릿(scriptlet) | <% … %> | 자바 로직 코드를 작성하는 데 사용 |
| 표현문(expression) | <%= … %> | 변수, 계산식, 메소드 호출 결과를 문자열 형태로 출력하는 데 사용 |
<%@page import="java.io.IOException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Hello Servlet/JSP, 뷁</h1>
<% // 스크립틀릿
out.println(dice());
myPrint(out);
%>
</body>
</html>
<%! // 선언문, 위치 아무데나 가능
public int dice() {
return (int)(Math.random() * 6) + 1;
}
public void myPrint(JspWriter out) throws IOException {
out.println("Hello declaration");
}
%>
<%! 자바 코드; %>
<%= 자바 코드 %>
JSP 주석과 HTML 주석 태그
웹 애플리케이션 배포하기