- κ΄λ ¨ κΈ
- [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 |
λκΈ