<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% request.setAttribute("text", "<b>내용입니다.</b>");
request.setAttribute("age", 20);%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
JSTL - out 태그<p>
<c:out value="안녕하세요<br>반가워요"/><br>
<c:out value="${requestScope.text }"/><br>
<c:out value="${requestScope.text }" escapeXml="false"/>
<hr>
null값 출력<br>
이름 : ${requestScope.name } <br>
이름 : <c:out value="${requestScope.name }" default="이름이 없습니다."/><br>
나이 : <c:out value="${requestScope.age }">나이가 없네요</c:out>
</body>
</html>
<%@page import="myjsp.dto.CustomerDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
error.jsp<br>
오류가 발생했습니다.<br>
관리자에게 문의하세요.. admin@abc.com<br>
<%
request.setAttribute("error_message", "~~~문제로 오류가 발생했습니다.");
session.setAttribute("login_info", new CustomerDTO("a","1","홍길동","이메일", 23));
%>
<c:if test="${ requestScope.error_message != null }">
오류메세지 : ${requestScope.error_message }<br>
</c:if>
<c:if test="${ not empty requestScope.error_message }">
오류메세지 : ${requestScope.error_message }<br>
</c:if>
<hr>
메뉴 : 마이페이지 QnA 장바구니
<c:if test= "${ sessionScope.login_info.age gt 19 }">
성인입장페이지
</c:if>
</body>
</html>
<%@page import="myjsp.dto.CustomerDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% session.setAttribute("login_info", new CustomerDTO("aa","11","김유신","a@a.com", 10)); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
메뉴 :
<c:choose>
<c:when test="${ empty sessionScope.login_info }">
로그인
</c:when>
<c:otherwise>
로그아웃 마이페이지
</c:otherwise>
</c:choose>
QnA 장바구니<br>
<c:if test="${ sessionScope.login_info != null }">
<c:choose>
<c:when test="${ sessionScope.login_info.age le 10 }">
어린이메뉴(10세이하)
</c:when>
<c:when test="${ sessionScope.login_info.age ge 11 and sessionScope.login_info.age le 19 }">
청소년메뉴(11~19)
</c:when>
<c:when test="${ sessionScope.login_info.age ge 20 }">
성인메뉴(20세 이상)
</c:when>
</c:choose>
</c:if>
</body>
</html>
<%@page import="java.util.HashMap"%>
<%@page import="myjsp.dto.CustomerDTO"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
forEach 태그를 이용한 Collection 반복<br>
<%
String [] names = {"이순신", "홍길동" , "김유신", "강감찬"};
request.setAttribute("names", names);
%>
1. 배열 반복<br>
<c:forEach items="${requestScope.names }" var="name" varStatus="cnt">
${cnt.count } - ${name }<br>
</c:forEach>
<hr>
<% ArrayList list = new ArrayList();
list.add(new CustomerDTO("aaa", "111", "유재석", "a@abc.com", 30));
list.add(new CustomerDTO("bbb", "222", "박명수", "b@abc.com", 40));
list.add(new CustomerDTO("aaa", "333", "정준하", "c@abc.com", 36));
request.setAttribute("list", list);
%>
2. ArrayList 반복<br>
<c:forEach items="${requestScope.list }" var="cto">
ID: ${cto.id }, Password : ${cto.password }, 이름 : ${cto.name }<br>
</c:forEach>
<% HashMap map = new HashMap();
map.put("name", "홍길동");
map.put("age", 30);
map.put("address", "서울");
request.setAttribute("map", map);
%>
<hr>
3. Map을 반복<br>
<c:forEach items="${requestScope.map }" var="entry">
${entry.key } - ${entry.value }<br>
</c:forEach>
나이만 조회<br>
<c:forEach items="${requestScope.map }" var="entry">
<c:if test="${entry.key == 'age' }">
나이는 ${entry.value }
</c:if>
</c:forEach>
<hr>
forEach 태그를 이용한 단순 반복<br>
<c:forEach begin="1" end="10" step="1" var="cnt">
${cnt } - 안녕하세요<br>
</c:forEach>
</body>
</html>