λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

Spring/Spring Quick Start

EL & JSTL λž€?

EL: Expression Language

JSP 2.0μ—μ„œ μƒˆλ‘œ μΆ”κ°€λœ 슀크립트 μ–Έμ–΄λ‘œμ„œ, 기쑴의 ν‘œν˜„μ‹μ„ λŒ€μ²΄ν•˜λŠ” ν‘œν˜„μ–Έμ–΄μ΄λ‹€.

예λ₯Ό λ“€μ–΄ session에 μ €μž₯λ˜μ–΄ μžˆλŠ” μ‚¬μš©μž 이름을 JSP 화면에 좜λ ₯ν•  λ•Œ, κΈ°μ‘΄μ—λŠ” μ•„λž˜μ™€ 같이 ν‘œν˜„ν–ˆλ‹€λ©΄,

<% session.getAttrivute("userName") %>

EL을 μ΄μš©ν•˜λ©΄ μ•„λž˜μ™€ 같이 ν‘œν˜„ν•  수 μžˆλ‹€.

${userName}

μ•„λž˜μ˜ μ½”λ“œμ—μ„œ κ°„κ°„νžˆ ${ } λ₯Ό μ΄μš©ν•˜μ—¬ 값을 μ“°κ³  μžˆλŠ” 것을 λ³Ό 수 μžˆλ‹€.

[ getBoard.jsp ]

<%@page contentType="text/html; charset=EUC-KR"%>

<!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=EUC-KR">
<title>κΈ€ 상세</title>
</head>
<body>
	<center>
		<h1>κΈ€ 상세</h1>
		<a href="logout.do">Log-out</a>
		<hr>
		<form action="updateBoard.do" method="post">
			<input name="seq" type="hidden" value="${board.seq}" />
			<table border="1" cellpadding="0" cellspacing="0">
				<tr>
					<td bgcolor="orange" width="70">제λͺ©</td>
					<td align="left"><input name="title" type="text"
						value="${board.title }" /></td>
				</tr>
				<tr>
					<td bgcolor="orange">μž‘μ„±μž</td>
					<td align="left">${board.writer }</td>
				</tr>
				<tr>
					<td bgcolor="orange">λ‚΄μš©</td>
					<td align="left"><textarea name="content" cols="40" rows="10">
						${board.content }</textarea></td>
				</tr>
				<tr>
					<td bgcolor="orange">등둝일</td>
					<td align="left">${board.regDate }</td>
				</tr>
				<tr>
					<td bgcolor="orange">쑰회수</td>
					<td align="left">${board.cnt }</td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="submit"
						value="κΈ€ μˆ˜μ •" /></td>
				</tr>
			</table>
		</form>
		<hr>
		<a href="insertBoard.jsp">글등둝</a>&nbsp;&nbsp;&nbsp; 
		<a href="deleteBoard.do?seq=${board.seq }">κΈ€μ‚­μ œ</a>&nbsp;&nbsp;&nbsp;
		<a href="getBoardList.do">κΈ€λͺ©λ‘</a>
	</center>
</body>
</html>

 

 

JSTL: JSP Standard Tag Library

JSP ν”„λ‘œκ·Έλž¨μ„ κ°œλ°œν•˜λ‹€ 보면 Scriptletμ—μ„œ if, for, switch λ“±κ³Ό 같은 μžλ°” μ½”λ“œλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•˜λŠ” λ•Œκ°€ μžˆλ‹€.

JSTL은 JSPμ—μ„œ μ‚¬μš©ν•΄μ•Ό ν•˜λŠ” 이런 μžλ°” μ½”λ“œλ“€μ„ νƒœκ·Έ ν˜•νƒœλ‘œ μ‚¬μš©ν•  수 μžˆλ„λ‘ μ§€μ›ν•œλ‹€.

 

μ•„λž˜μ˜ μ½”λ“œμ—μ„œ for 루프 λŒ€μ‹  <c:forEach> νƒœκ·Έλ₯Ό μ‚¬μš©ν•œ 것을 λ³Ό 수 μžˆλ‹€.

<c:forEach> νƒœκ·Έλ₯Ό μ‚¬μš©ν•˜κΈ° μœ„ν•΄ λ‘λ²ˆμ§Έ 쀄에 taglib μ§€μ‹œλ¬Έμ΄ μΆ”κ°€λ˜μ—ˆλ‹€.

<%@page contentType="text/html; charset=EUC-KR"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!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=EUC-KR">
<title>κΈ€ λͺ©λ‘</title>
</head>
<body>
	<center>
		<h1>κΈ€ λͺ©λ‘</h1>
		<h3>
			ν…ŒμŠ€νŠΈλ‹˜ ν™˜μ˜ν•©λ‹ˆλ‹€...<a href="logout.do">Log-out</a>
		</h3>
		<!-- 검색 μ‹œμž‘ -->
		<form action="getBoardList.jsp" method="post">
			<table border="1" cellpadding="0" cellspacing="0" width="700">
				<tr>
					<td align="right"><select name="searchCondition">
							<option value="TITLE">제λͺ©
							<option value="CONTENT">λ‚΄μš©
					</select> <input name="searchKeyword" type="text" /> <input type="submit"
						value="검색" /></td>
				</tr>
			</table>
		</form>
		<!-- 검색 μ’…λ£Œ -->
		<table border="1" cellpadding="0" cellspacing="0" width="700">
			<tr>
				<th bgcolor="orange" width="100">번호</th>
				<th bgcolor="orange" width="200">제λͺ©</th>
				<th bgcolor="orange" width="150">μž‘μ„±μž</th>
				<th bgcolor="orange" width="150">등둝일</th>
				<th bgcolor="orange" width="100">쑰회수</th>
			</tr>
			<c:forEach items="${boardList }" var="board">
				<tr>
					<td>${board.seq }</td>
					<td align="left"><a href="getBoard.do?seq=${board.seq }">
							${board.title }</a></td>
					<td>${board.writer }</td>
					<td>${board.regDate }</td>
					<td>${board.cnt }</td>
				</tr>
			</c:forEach>
		</table>
		<br> <a href="insertBoard.jsp">μƒˆκΈ€ 등둝</a>
	</center>
</body>
</html>