JSP/JSP 이용하기

[JSP] JSP contentType 변경해서 사용해보기

h0-0cat 2023. 6. 7. 11:58
728x90

<%-- 나는 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>

실행 결과

 


 

 

 

 

 

728x90