<%-- 나는 JSP 주석입니다. --%>
%@로 시작되면 디렉티브라고 한다. 설정 정보를 지정할때 사용한다.
page 디렉티브 ------------- contentType="생성할 문서형식;
인코딩타입" : 이 JSP파일이 실행되고 만들어질 문서의 형시과 인코딩 방식 지정
contentType="text/plain; charset=UTF-8" : 실행결과가 text문서이다.
contentType="text/html; charset=UTF-8" : 실행결과가 html문서이다.
contentType="application/json; charset=UTF-8" : 실행결과가 json문서이다.
contentType="application/xml; charset=UTF-8" : 실행결과가 xml문서이다.
trimDirectiveWhitespaces="true" : 페이지 상단의 쓸데없는 빈줄을 지워준다.
text.jsp
contentType text/plain으로 변경
<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 긁지않은개발자 --%>
<%@ page contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Hello JSP!!!</h1>
</body>
</html>
실행 결과

html
contentType text/html으로 변경
contentType="text/html; charset=UTF-8" : 실행결과가 html문서이다.
<%-- 긁지않은개발자 --%>
실행 결과
json.jsp
contentType json으로 변경
<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 긁지않은개발자 --%>
<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
{
"name" : "한사람",
"age" : 34,
"gender" : true
}
실행 결과

xml.jsp
contentType xml으로 변경
<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 긁지않은개발자 --%>
<%@ page contentType="application/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<computer>
<cpu>386</cpu>
<ram>8GB</ram>
<hdd>1TB</hdd>
</computer>
실행 결과
'JSP > JSP 이용하기' 카테고리의 다른 글
[JSP] JSP 이용해서 간단한 회원가입 화면 만들기(입력된 정보 웹페이지출력하기까지 +) (0) | 2023.06.07 |
---|---|
[JSP] JSP파일로 Cookie(쿠키) 정보 읽어보기 (0) | 2023.06.07 |
[JSP] JSP URL에 입력해서 메세지 출력 (이름,나이) (0) | 2023.06.07 |
[JSP] JSP(JavaServer Pages )로 현재시간 출력해보기 (0) | 2023.06.07 |
[JSP] JSP이용해서 구구단 출력 (0) | 2023.06.06 |