- ๊ด๋ จ ๊ธ
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (1) ํ์ ๋ชฉ๋ก ์กฐํ
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (2) ํ์ ๊ฐ์
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (3) ํ์ ์ ๋ณด ์์
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (4) ๋ทฐ(JSP) ๋ถ๋ฆฌํ๊ธฐ
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (5) ๋ก๊ทธ์ธ/๋ก๊ทธ์์(HttpSession)
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (6) ํ์ ์ญ์
[IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (6) ํ์ ์ญ์
๋ฑ๋ก๋ ํ์ ์ค ์ ํํ ํ์์ ์ญ์ ํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ค.
๊ด๋ฆฌ์๋ง ์ญ์ ํ ์ ์๋๋ก ํ ๊ฒ์ด๋ค.
1. ํ์ ๋ชฉ๋ก JSP ๋ณ๊ฒฝ
ํ์ ์ ๋ณด ์์ '์ญ์ ' ๋ฒํผ์ ์ถ๊ฐํ๋ค.
StudentList.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" language="java" %>
<%
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>
<%--<jsp:useBean id="students" scope="request" class="java.util.ArrayList" type="java.util.List<com.atoz_develop.spms.vo.Student>" />--%>
<%
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 |
session์์ ๋ก๊ทธ์ธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์์ admin์ด๋ฉด ์ญ์ ๋ฒํผ์ ์ถ๋ ฅํ๋ค.
์ญ์ ๋ฒํผ ํด๋ฆญ ์ /student/delete๋ก GET ์์ฒญ์ ๋ณด๋ธ๋ค.
์ญ์ ํ ํ์์ ํ๋ฒ(student_no)์ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ก ํจ๊ป ๋ณด๋ธ๋ค.
ํ์ ์ ๋ณด ์์ JSP์๋ ์ญ์ ๋ฒํผ์ ์ถ๊ฐํ๋ค.
StudentUpdateForm.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
|
<%@ page import="com.atoz_develop.spms.vo.Student" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
Student loginMember = (Student) session.getAttribute("student");
Student student = (Student) request.getAttribute("student");
%>
<html>
<head>
<title>ํ์ ์ ๋ณด</title>
</head>
<body>
<h1>ํ์์ ๋ณด</h1>
<form action='update' method='post'>
ํ๋ฒ: <input type='text' name='student_no' value='<%=student.getStudentNo()%>' readonly><br>
ํ๊ณผ: <input type='text' name='department' value='<%=student.getDepartment()%>'><br>
์ด๋ฆ: <input type='text' name='student_name' value='<%=student.getStudentName()%>'><br>
ํ๋
: <input type='text' name='grade' value='<%=student.getGrade()%>' readonly><br>
์ฑ๋ณ: <input type='text' name='gender' value='<%=student.getGender()%>' readonly><br>
๋์ด: <input type='text' name='age' value='<%=student.getAge()%>' readonly><br>
์ ํ๋ฒํธ: <input type='text' name='phone_number' value='<%=student.getPhoneNumber()%>'><br>
์ฃผ์: <input type='text' name='address' value='<%=student.getAddress()%>'><br>
<input type='submit' value='์์ '>
<%
if(loginMember != null && "admin".equals(loginMember.getStudentNo())) {
%>
<input type="button" value="์ญ์ " onClick="location.href='delete?student_no=<%=student.getStudentNo()%>'" />
<%
}
%>
<input type='button' value='์ทจ์' onClick='location.href="list"'>
</form>
</body>
</html>
|
cs |




2. ์ญ์ ์๋ธ๋ฆฟ ์์ฑ
StudentDeleteServlet.java
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
|
@WebServlet("/student/delete")
public class StudentDeleteServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Connection conn = null;
PreparedStatement pstmt = null;
ServletContext sc = req.getServletContext();
try {
conn = (Connection) sc.getAttribute("conn");
pstmt = conn.prepareStatement(
"DELETE FROM STUDENT WHERE STUDENT_NO = ?"
);
pstmt.setString(1, req.getParameter("student_no"));
if(pstmt.executeUpdate() > 0) {
resp.sendRedirect("list");
} else {
throw new SQLException();
}
} catch (SQLException e) {
req.setAttribute("error", e);
RequestDispatcher rd = req.getRequestDispatcher("/Error.jsp");
rd.forward(req, resp);
} finally {
try {
if(pstmt != null) pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
|
cs |
์ญ์ ๊ฐ ์๋ฃ๋๋ฉด ํ์ ๋ชฉ๋ก์ผ๋ก ๋ฆฌ๋ค์ด๋ ํธํ๊ณ ์๋ฌ ๋ฐ์ ์ Error.jsp ํ์ด์ง๋ก ํฌ์๋ฉํ๋๋ก ํ์๋ค.
- ๊ด๋ จ ๊ธ
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (1) ํ์ ๋ชฉ๋ก ์กฐํ
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (2) ํ์ ๊ฐ์
- [IntelliJ] ํ์๊ฐ์ ์์ (JAVA + MySQL) - (3) ํ์ ์ ๋ณด ์์
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (4) ๋ทฐ(JSP) ๋ถ๋ฆฌํ๊ธฐ
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (5) ๋ก๊ทธ์ธ/๋ก๊ทธ์์(HttpSession)
- [IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (6) ํ์ ์ญ์
'Javaยท๏ปฟServletยท๏ปฟJSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JSP - EL ํํ์ ๋ฌธ๋ฒ๊ณผ ์ฌ์ฉ ๋ฐฉ๋ฒ (3) | 2020.02.13 |
---|---|
์๋ธ๋ฆฟ ๋ฐ์ดํฐ ๋ณด๊ด์ - ServletContext, HttpSession, ServletRequest, JspContext (0) | 2020.02.13 |
[IntelliJ] ํ์๊ฐ์ ์์ (MVC) - (5) ๋ก๊ทธ์ธ/๋ก๊ทธ์์(HttpSession) (0) | 2020.02.13 |
JSP ์ก์ ํ๊ทธ์ jsp:useBean ์ฌ์ฉ ์์ (0) | 2020.02.13 |
ServletContext๋ก DB ์ปค๋ฅ์ ๊ฐ์ฒด ๊ด๋ฆฌํ๊ธฐ (0) | 2020.02.12 |
๋๊ธ