C 태그(Core 태그)
<c:out>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- taglib 설정 필수 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>회원 리스트</h1>
<table border="1" width="70%">
<tr>
<td>이름</td>
<td>email</td>
</tr>
<c:forEach var="m" items="${members}">
<tr>
<td><c:out value="${m.name}"/> / ${m.name} </td>
<td><c:out value="${m.email}" escapeXml="false">
<span style="color:red;">이메일 없음</span>
</c:out>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<c:if>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- taglib 설정 필수 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>회원 리스트</h1>
<table border="1" width="70%">
<tr>
<td>이름</td>
<td>email</td>
</tr>
<%-- <c:if test="${members != null }"></c:if> --%>
<c:forEach var="m" items="${members}">
<tr>
<td><c:out value="${m.name}" /> / ${m.name} /
<c:if test="${m.name=='김왕건1'}">
<span style="color: blue;">이벤트 당첨자</span>
</c:if>
</td>
<td>
<c:if test="${m.email!=null}">
${m.email}
</c:if>
<c:if test="${m.email==null}">
<span style="color: green;">email not found</span>
</c:if>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<c:choose>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- taglib 설정 필수 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<form> <!-- action값 지정x -> 본인 페이지로 reback -->
<select name="sel">
<option value="a" ${param.sel == 'a'? 'selected' : ' '}>a</option>
<option value="b" ${param.sel == 'b'? 'selected' : ' '}>b</option>
<option value="c" ${param.sel == 'c'? 'selected' : ' '}>c</option>
</select> <input type="submit" value="전송">
</form>
<hr> <!-- 줄 긋기 -->
<c:choose>
<c:when test="${param.sel == 'a'}">
a 선택
</c:when>
<c:when test="${param.sel == 'b'}">
b 선택
</c:when>
<c:when test="${param.sel == 'c'}">
c 선택
</c:when>
<c:otherwise>
잘못 선택하셨습니다.
</c:otherwise>
</c:choose>
</body>
</html>
<c:forEach>
[cforeach.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- taglib 설정 필수 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>회원 리스트</h1>
<table border="1" width="70%">
<tr>
<td>index</td>
<td>count</td>
<td>이름</td>
<td>email</td>
</tr>
<c:forEach var="m" items="${members}" begin="1" end="3" varStatus="status" >
<tr>
<td>${status.index}</td>
<td>${status.count}</td>
<td><c:out value="${m.name}"/> / ${m.name} </td>
<td><c:out value="${m.email}" escapeXml="false">
<span style="color:red;">이메일 없음</span>
</c:out>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<c:forTokens>
[cforeach.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- taglib 설정 필수 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>회원 리스트</h1>
<table border="1" width="70%">
<tr>
<td>index</td>
<td>count</td>
<td>이름</td>
<td>email</td>
</tr>
<c:forEach var="m" items="${members}" begin="1" end="3" varStatus="status" >
<tr>
<td>${status.index}</td>
<td>${status.count}</td>
<td><c:out value="${m.name}"/> / ${m.name} </td>
<td><c:out value="${m.email}" escapeXml="false">
<span style="color:red;">이메일 없음</span>
</c:out>
<br>
<c:forTokens items="${m.email}" delims="@" var="email" varStatus="s">
<c:if test="${s.index == 0 }"> 아이디: </c:if>
<c:if test="${s.index == 1 }">, 도메인: </c:if>
${email}
</c:forTokens>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<c:url>
[index.jsp]
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.util.ArrayList"%>
<%@page import="member.Member"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
List<Member> members = new ArrayList<Member>();
members.add(new Member("김왕건1","wang@gmail.com"));
members.add(new Member("김왕건2","wang@gmail.com"));
members.add(new Member("김왕건3","wang@gmail.com"));
members.add(new Member("김왕건4",null));
members.add(new Member("김왕건5",null));
session.setAttribute("members", members); //session에 저장->다른페이지에서도 공유 가능
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>INDEX</h1>
<h3>members 등록, 저장</h3>
<p><p>
<h2><c:url value="/cout.jsp"/></h2>
<a href="cout.jsp">out 태그 확인</a>
<a href="cif.jsp">if 태그 확인</a>
<a href="cchoose.jsp">choose 태그 확인</a>
<a href="cforeach.jsp">forEach 태그 확인</a>
</body>
</html>
<c:param>
<%@page import="java.util.ArrayList"%>
<%@page import="member.Member"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
List<Member> members = new ArrayList<Member>();
members.add(new Member("김왕건1","wang@gmail.com"));
members.add(new Member("김왕건2","wang@gmail.com"));
members.add(new Member("김왕건3","wang@gmail.com"));
members.add(new Member("김왕건4",null));
members.add(new Member("김왕건5",null));
session.setAttribute("members", members); //session에 저장->다른페이지에서도 공유 가능
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<h1>INDEX</h1>
<h3>members 등록, 저장</h3>
<p><p>
<h2>
<c:url value="/cout.jsp" var="alink">
<c:param name="name">scott</c:param>
</c:url>
</h2>
<!-- /cout.jsp?name=scott -->
<a href="${alink}">out 태그 확인</a>
<a href="cif.jsp">if 태그 확인</a>
<a href="cchoose.jsp">choose 태그 확인</a>
<a href="cforeach.jsp">forEach 태그 확인</a>
</body>
</html>
<c:redirect>
<%@ 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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
</style>
</head>
<body>
<c:redirect url="/cchoose.jsp"> <!-- /cchoose.jsp?sel=b -->
<c:param name="sel">b</c:param>
</c:redirect>
</body>
</html>
댓글 없음:
댓글 쓰기