Web/JSP
JSP) 스파게티코드 vs out객체 활용 (예제)
surhommejk
2018. 3. 20. 14:39
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WAS 내장 객체(out)</title>
</head>
<body>
// 스파게티 코드
<%
boolean b = true;
if(10 > 5){
%>
IF(true):<font color="red"><%=b%></font>
<%
}else{
b = false;
%>
IF(false):<font color="blue"><%=b%></font>
<%
}
%>
// out 객체 활용
<%
boolean b2= true;
if(10 > 5){
out.print("IF(true):<font color='red'>" + b2 + "</font>");
}else{
out.print("IF(false):<font color='blue'>" + b2 + "</font>");
}
%>
</body>
</html>
+ out 객체 method 정리
print() - 데이터를 출력한다.
println() - 데이터를 출력하고, \r\n(또는 \n)을 출력한다.
newLine() - \r\n(또는 \n)을 출력한다.
int getBufferSize() - 버퍼의 크기를 구한다.
int getRemaining() - 현재 버퍼의 남은 크기를 구한다.
clear() - 버퍼의 내용을 비운다. 만약 버퍼가 이미 플러시 되었다면 IOException을 발생시킨다.
clearBuffer() - 버퍼의 내용을 비운다.
flush() - 버퍼를 플러시 한다.
boolean isAutoFlush() - 버퍼가 다 찼을 때 자동으로 플러시 할 경우 true를 리턴한다.