κ΅λΉμ§μ D+78
κ³Όμ νκ°ν μ 보μ²λ¦¬μ°μ κΈ°μ¬
- νμμμ νλ©΄(modify.jsp) ꡬν -
νμμμ νλ©΄(modify.jsp) ꡬν
νμμμ νλ©΄μ μ¬μ€μ νμλ±λ‘(register.jsp)κ³Ό κ±°μ μΌμΉνλ€.
λ¨, νμμμ νλ©΄μ ν΄λ¦ν νμμ μ 보λ₯Ό λΆλ¬μ textboxμ κ°μ λ£μ΄μ£Όμ΄μΌνλ€λ κ²μ΄λ€.
• modify.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.Date" %>
<%@ page import="DBPKG.DBConnection" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>νμΌν νμ μμ </title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<div>
<h2>μΌνλͺ° νμκ΄λ¦¬ ver 1.0</h2>
</div>
</header>
<nav>
<div>
<a href="register.jsp">νμλ±λ‘</a>
<a href="inquiry.jsp">νμλͺ©λ‘μ‘°ν/μμ </a>
<a href="sale.jsp">νμ맀μΆμ‘°ν</a>
<a href="index.jsp">νμΌλ‘</a>
</div>
</nav>
<section>
<div>
<h3>νμΌν νμ μ 보 μμ </h3>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
request.setCharacterEncoding("UTF-8");
String custno = request.getParameter("custno");
String custname = "";
String phone = "";
String address = "";
Date joindate = null;
String grade = "";
String city = "";
String sql = "select * from member_tbl_02 where custno=" + custno;
try
{
conn = DBConnection.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery(sql);
while(rset.next())
{
custname = rset.getString("custname");
phone = rset.getString("phone");
address = rset.getString("address");
joindate = rset.getDate("joindate");
grade = rset.getString("grade");
city = rset.getString("city");
}
rset.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println("[Error] " + e.getMessage());
e.printStackTrace();
}
%>
<form method="post" id="frm_modify" name="frmModify">
<table border="1" style="width: 550px">
<tr>
<th>νμλ²νΈ</th>
<td><input type="text" value=<%= custno %> readonly name="custno"></td>
</tr>
<tr>
<th>νμμ±λͺ
</th>
<td><input type="text" id="custname" name="custname" value=<%= custname %>></td>
</tr>
<tr>
<th>νμμ ν</th>
<td><input type="text" id="phone" name="phone" value=<%= phone %>></td>
</tr>
<tr>
<th>νμμ£Όμ</th>
<td><input type="text" id="address" name="address" value="<%= address %>"></td>
</tr>
<tr>
<th>κ°μ
μΌμ</th>
<td><input type="text" id="joindate" name="joindate" value=<%= joindate %>></td>
</tr>
<tr>
<th>κ³ κ°λ±κΈ[A:VIP, B:μΌλ°, C:μ§μ]</th>
<td><input type="text" id="grade" name="grade" value=<%= grade %>></td>
</tr>
<tr>
<th>λμμ½λ</th>
<td><input type="text" id="city" name="city" value=<%= city %>></td>
</tr>
</table>
</form>
<table border="1" style="width: 550px">
<tr>
<td>
<input type="button" id="btn_modify" value="μμ ">
<input type="button" id="btn_inquiry" value="μ‘°ν">
</td>
</tr>
</table>
</div>
</section>
<footer>
<div>
<h4>HRDKOREA Copyright@2016 All rights reserved. Human Resources Development Service of Korea</h4>
</div>
</footer>
<iframe name="hiddenframe" style="display: none"></iframe>
<script>
(function(){
const btnModify = document.querySelector("#btn_modify");
const btnInquiry = document.querySelector("#btn_inquiry");
const frmModify = document.querySelector("#frm_modify");
const objsArr = [
{elem: document.querySelector("#custname"), size: 20, blankMsg: "νμμ±λͺ
μ΄ μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "νμμ±λͺ
μ΄ μ¬λ°λ₯΄μ§ μμ΅λλ€."},
{elem: document.querySelector("#phone"), size: 13, blankMsg: "νμμ νκ° μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "νμμ νκ° μ¬λ°λ₯΄μ§ μμ΅λλ€."},
{elem: document.querySelector("#address"), size: 60, blankMsg: "μ£Όμκ° μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "μ£Όμκ° μ¬λ°λ₯΄μ§ μμ΅λλ€."},
{elem: document.querySelector("#joindate"), size: 10, blankMsg: "κ°μ
μΌμκ° μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "κ°μ
μΌμκ° μ¬λ°λ₯΄μ§ μμ΅λλ€."},
{elem: document.querySelector("#grade"), size: 1, blankMsg: "κ³ κ°λ±κΈμ΄ μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "κ³ κ°λ±κΈμ΄ μ¬λ°λ₯΄μ§ μμ΅λλ€."},
{elem: document.querySelector("#city"), size: 2, blankMsg: "κ±°μ£Όλμκ° μ
λ ₯λμ§ μμμ΅λλ€.", validMsg: "κ±°μ£Όλμκ° μ¬λ°λ₯΄μ§ μμ΅λλ€."}
];
const checkBlank = function()
{
let result = true;
for(let i = 0; i < objsArr.length; i++)
{
if(objsArr[i].elem.value.length === 0) return i;
}
return result;
}
const checkValid = function()
{
let result = true;
for(let i = 0; i < objsArr.length; i++)
{
if(objsArr[i].elem.value.length > objsArr[i].size) return i;
}
if(isNaN(objsArr[3].elem.value.replaceAll("-", "")) === true) return 3;
if(isNaN(objsArr[4].elem.value) === false) return 4;
if(isNaN(objsArr[5].elem.value) === true) return 5;
return result;
}
btnModify.addEventListener("click", function()
{
let res = checkBlank();
if(res !== true)
{
alert(objsArr[res].blankMsg);
objsArr[res].elem.focus();
return;
}
res = checkValid();
if(res !== true)
{
alert(objsArr[res].validMsg);
objsArr[res].elem.focus();
return;
}
frmModify.action = "update.jsp";
frmModify.target = "hiddenframe";
frmModify.submit();
});
btnInquiry.addEventListener("click", function(){
location.href = "./inquiry.jsp";
});
})();
</script>
</body>
</html>
• update.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="DBPKG.DBConnection" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DB νμμμ </title>
</head>
<body>
<%
Connection conn = null;
Statement stmt = null;
request.setCharacterEncoding("UTF-8");
String custno = request.getParameter("custno");
String custname = request.getParameter("custname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String joindate = request.getParameter("joindate");
String grade = request.getParameter("grade");
String city = request.getParameter("city");
joindate = joindate.replaceAll("-", "");
String sql = "update member_tbl_02 set " +
"custname= '" + custname + "', " +
"phone= '" + phone + "', " +
"address= '" + address + "', " +
"joindate= to_date('" + joindate + "', 'YYYYMMDD'), " +
"grade= '" + grade + "', " +
"city= '" + city + "' " +
"where custno= " + custno;
int result = 0;
try
{
conn = DBConnection.getConnection();
stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
if(conn.getAutoCommit() == false) conn.commit();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println("[Error] " + e.getMessage());
e.printStackTrace();
}
finally
{
out.println("<h1>" + result + "</h1>");
}
%>
<script>
(function(){
const h1Elem = document.querySelector("h1");
if(h1Elem.textContent === "1")
{
alert("νμμμ μ΄ μλ£λμμ΅λλ€.");
}
else
{
alert("νμμμ μ΄ μ§νλμ§ μμμ΅λλ€.");
}
parent.location.reload();
})();
</script>
</body>
</html>
λ°μν
λκΈ