JSP/EL
chapter01 : attribute
GAWON
2023. 5. 24. 09:22
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//1~100값의 총 합 출력
int total = 0;
for(int i=0; i<101; i++){
total +=i;
}
// key , value
pageContext.setAttribute("TOTAL", total);//pageContext속성에 setAttribute저장
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>1~100사이의 모든 정수의 합은<%=total %></h1> <!-- 표현식 -->
<h1>1~100사이의 모든 정수의 합은<%=pageContext.getAttribute("TOTAL")%></h1>
<h1>1~100사이의 모든 정수의 합은${TOTAL }</h1> <!-- 속성명이TOTAL이라면 그대로 가져다 쓸수있다(가독성이좋다) -->
</body>
</html>