- ๊ด๋ จ ๊ธ
- [JSP] JSTL ์ฌ์ฉ ๋ฐฉ๋ฒ - ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ค์ด๋ก๋ ๋ฐ ์ธํ
- [JSP] JSTL ์ฌ์ฉ ๋ฐฉ๋ฒ - ์ฃผ์ ํ๊ทธ ๋ฌธ๋ฒ ์ ๋ฆฌ
[JSP] JSTL ํ์ฉ ๋ฐฉ๋ฒ - JSP์์ ์๋ฐ ์ฝ๋ ์ ๊ฑฐ
๋ค์์ ํ์ ๋ชฉ๋ก์ ์ถ๋ ฅํ๋ JSP์ด๋ค. JSTL, EL์ ์ฌ์ฉํด์ ์ด JSP์์ ์ฌ์ฉ๋ ๋ชจ๋ ์๋ฐ์ฝ๋์ ํํ์ <%= %>์ ์์จ ๊ฒ์ด๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<%@ page import="com.atoz_develop.spms.vo.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
Student loginMember = (Student) session.getAttribute("student");
%>
<html>
<head>
<title>ํ์ ๋ชฉ๋ก</title>
</head>
<body>
<jsp:include page="/Header.jsp"/>
<h1>ํ์ ๋ชฉ๋ก</h1>
<p><a href="add">์ ๊ท ํ์</a></p>
<%
List<Student> students = (ArrayList<Student>)request.getAttribute("students");
for(Student student: students) {
if(loginMember != null && "admin".equals(loginMember.getStudentNo())) {
%>
<input type="button" value="์ญ์ " onClick="location.href='delete?student_no=<%=student.getStudentNo()%>'" />
<%
}
%>
<%=student.getStudentNo()%>,
<%=student.getDepartment()%>,
<a href="update?student_no=<%=student.getStudentNo()%>"><%=student.getStudentName()%></a>,
<%=student.getGrade()%>,
<%=student.getGender()%>,
<%=student.getAge()%>,
<%=student.getPhoneNumber()%>,
<%=student.getAddress()%><br>
<%
}
%>
<jsp:include page="/Tail.jsp"/>
</body>
</html>
|
cs |
์ฐ์ import ์ง์์์ loginMember, students๋ฅผ ๊ฐ์ ธ์ค๋ ์ฝ๋, for๋ฌธ์ ์ ๊ฑฐํ๋ค.
๊ทธ๋ฆฌ๊ณ JSTL Core ํ๊ทธ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ taglib ์ง์์๋ฅผ ์ ์ธํ๋ค.
for๋ฌธ์ <c:forEach>๋ก, if๋ฌธ์ <c:if>๋ก ๋์ฒดํ๊ณ ๊ฐ์ ์ถ๋ ฅํ๋ ํํ์ <%= %>์ EL ํํ์์ผ๋ก ๋์ฒดํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>ํ์ ๋ชฉ๋ก</title>
</head>
<body>
<jsp:include page="/Header.jsp"/>
<h1>ํ์ ๋ชฉ๋ก</h1>
<p><a href="add">์ ๊ท ํ์</a></p>
<c:forEach var="student" items="${students}">
<c:if test="${sessionScope.student.studentNo == 'admin'}">
<input type="button" value="์ญ์ " onClick="location.href='delete?student_no=${student.studentNo}'" />
</c:if>
${student.studentNo},
${student.department},
<a href="update?student_no=${student.studentNo}">${student.studentName}</a>,
${student.grade},
${student.gender},
${student.age},
${student.phoneNumber},
${student.address}<br>
</c:forEach>
<jsp:include page="/Tail.jsp"/>
</body>
</html>
|
cs |
์ด์ ์ด jsp ํ์ผ์๋ ์๋ฐ ์ฝ๋๊ฐ ์์ ํ ์ ๊ฑฐ๋์ด ์์ค๊ฐ ํจ์ฌ ๊ฐ๊ฒฐํ๊ณ ์ง๊ด์ ์ด๋ฉฐ ์ ์ง๋ณด์ํ๊ธฐ ์ฝ๊ฒ ๋ฐ๋์๋ค.
- ๊ด๋ จ ๊ธ
- [JSP] JSTL ์ฌ์ฉ ๋ฐฉ๋ฒ - ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ค์ด๋ก๋ ๋ฐ ์ธํ
'Javaยท๏ปฟServletยท๏ปฟJSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ServletContextListener๋ก DB ์ปค๋ฅ์ , DAO ๊ณต์ ๊ฐ์ฒด ๊ด๋ฆฌํ๊ธฐ (0) | 2020.02.15 |
---|---|
[IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (7) DAO ๋ถ๋ฆฌํ๊ธฐ (0) | 2020.02.15 |
[JSP] JSTL ์ฌ์ฉ ๋ฐฉ๋ฒ - ์ฃผ์ ํ๊ทธ ๋ฌธ๋ฒ ์ ๋ฆฌ (4) | 2020.02.15 |
JSP - EL ํํ์ ๋ฌธ๋ฒ๊ณผ ์ฌ์ฉ ๋ฐฉ๋ฒ (3) | 2020.02.13 |
์๋ธ๋ฆฟ ๋ฐ์ดํฐ ๋ณด๊ด์ - ServletContext, HttpSession, ServletRequest, JspContext (0) | 2020.02.13 |
๋๊ธ