JSP 게시판 만들기 - 삭제
페이지 정보
본문
[ delete.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
int idx = Integer.parseInt(request.getParameter("idx"));
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
<script language = "javascript"> // 자바 스크립트 시작
<script language = "javascript"> // 자바 스크립트 시작
function deleteCheck() {
var form = document.deleteform;
if( !form.password.value ) {
alert( "비밀번호를 적어주세요" );
form.password.focus();
return;
}
form.submit();
}
</script>
</head>
<body>
<table>
<tr>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr style="background:url('img/table_mid.gif') repeat-x; text-align:center;">
<td width="5"><img src="img/table_left.gif" width="5" height="30" /></td>
<td>삭제</td>
<td width="5"><img src="img/table_right.gif" width="5" height="30" /></td>
</tr>
</table>
<form name="deleteform" method="post" action="delete_ok.jsp?idx=<%=idx%>">
<table>
<tr>
<td> </td>
<td align="center">비밀번호</td>
<td><input name="password" type="password" size="50" maxlength="100"></td>
<td> </td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="4"></td></tr>
<tr height="1" bgcolor="#82B5DF"><td colspan="4"></td></tr>
<tr align="center">
<td> </td>
<td colspan="2">
<input type="button" value="삭제" onClick="javascript:deleteCheck();">
<input type="button" value="취소" onClick="javascript:history.back(-1)">
</td>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
[ delete_ok.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<meta charset="utf-8">
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
String password = null;
int idx = Integer.parseInt(request.getParameter("idx"));
String passw = request.getParameter("password");
try{
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select passowrd from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(password.equals(passw)) {
sql = "delete from board where idx=" + idx;
stmt.executeUpdate(sql);
%>
<script language=javascript>
self.window.alert("해당 글을 삭제하였습니다.");
location.href="list.jsp";
</script>
<%
rs.close();
stmt.close();
conn.close();
} else {
%>
<script language=javascript>
self.window.alert("비밀번호를 틀렸습니다.");
location.href="javascript:history.back()";
</script>
<%
}
} catch(SQLException e) {
out.println( e.toString() );
}
%>
자료출처
http://seinarin.tistory.com/8
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
int idx = Integer.parseInt(request.getParameter("idx"));
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
<script language = "javascript"> // 자바 스크립트 시작
<script language = "javascript"> // 자바 스크립트 시작
function deleteCheck() {
var form = document.deleteform;
if( !form.password.value ) {
alert( "비밀번호를 적어주세요" );
form.password.focus();
return;
}
form.submit();
}
</script>
</head>
<body>
<table>
<tr>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr style="background:url('img/table_mid.gif') repeat-x; text-align:center;">
<td width="5"><img src="img/table_left.gif" width="5" height="30" /></td>
<td>삭제</td>
<td width="5"><img src="img/table_right.gif" width="5" height="30" /></td>
</tr>
</table>
<form name="deleteform" method="post" action="delete_ok.jsp?idx=<%=idx%>">
<table>
<tr>
<td> </td>
<td align="center">비밀번호</td>
<td><input name="password" type="password" size="50" maxlength="100"></td>
<td> </td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="4"></td></tr>
<tr height="1" bgcolor="#82B5DF"><td colspan="4"></td></tr>
<tr align="center">
<td> </td>
<td colspan="2">
<input type="button" value="삭제" onClick="javascript:deleteCheck();">
<input type="button" value="취소" onClick="javascript:history.back(-1)">
</td>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
[ delete_ok.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<meta charset="utf-8">
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
String password = null;
int idx = Integer.parseInt(request.getParameter("idx"));
String passw = request.getParameter("password");
try{
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select passowrd from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(password.equals(passw)) {
sql = "delete from board where idx=" + idx;
stmt.executeUpdate(sql);
%>
<script language=javascript>
self.window.alert("해당 글을 삭제하였습니다.");
location.href="list.jsp";
</script>
<%
rs.close();
stmt.close();
conn.close();
} else {
%>
<script language=javascript>
self.window.alert("비밀번호를 틀렸습니다.");
location.href="javascript:history.back()";
</script>
<%
}
} catch(SQLException e) {
out.println( e.toString() );
}
%>
자료출처
http://seinarin.tistory.com/8
댓글목록
등록된 댓글이 없습니다.