JSP 게시판 만들기 - 수정
페이지 정보
본문
[ modify.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
String name = "";
String password = "";
String title = "";
String memo = "";
int idx = Integer.parseInt(request.getParameter("idx"));
try {
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select name, password, title, memo from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
name = rs.getString(1);
password = rs.getString(2);
title = rs.getString(3);
memo = rs.getString(4);
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException e) {
out.println( e.toString() );
}
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
<script language = "javascript"> // 자바 스크립트 시작
function writeCheck() {
var form = document.modifyform;
if( !form.name.value ) { // form 에 있는 name 값이 없을 때
alert( "이름을 적어주세요" ); // 경고창 띄움
form.name.focus(); // form 에 있는 name 위치로 이동
return;
}
if( !form.password.value ) {
alert( "비밀번호를 적어주세요" );
form.password.focus();
return;
}
if( !form.title.value ) {
alert( "제목을 적어주세요" );
form.title.focus();
return;
}
if( !form.memo.value ) {
alert( "내용을 적어주세요" );
form.memo.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=modifyform method="post" action="modify_ok.jsp">
<input type="hidden" name="idx" vaule="<%=idx%>">
<table width="100%">
<tr>
<td align="center">제목</td>
<td><input name="title" size="50" maxlength="100" vaule="<%=title%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">이름</td>
<td><input name="name" size="50" maxlength="50" vaule="<%=name%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">비밀번호</td>
<td><input name="password" size="50" maxlength="50" vaule="<%=passowrd%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">내용</td>
<td><textarea name="memo" cols="50" rows="13"><%=memo%></textarea></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr height="1" bgcolor="#82B5DF"><td colspan="2"></td></tr>
<tr align="center">
<td colspan="2">
<input type=button value="수정" OnClick="javascript:modifyCheck();">
<input type=button value="취소" OnClick="javascript:history.back(-1)">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
[ modify_ok.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
try{
request.setCharacterEncoding("utf-8");
int idx = Integer.parseInt(request.getParameter("idx"));
String title = request.getParameter("title");
String memo = request.getParameter("memo");
String passw = request.getParameter("password");
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select password from board wherer idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
password = rs.getString(1);
}
if(password.equals(passw)) {
sql = "update board set title='" + title+ "' , memo='"+ memo +"' where idx=" + idx;
stmt.executeUpdate(sql);
%>
<script language=javascript>
self.window.alert("글이 수정되었습니다.");
location.href="view.jsp?idx=<%=idx%>";
</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/9
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
String name = "";
String password = "";
String title = "";
String memo = "";
int idx = Integer.parseInt(request.getParameter("idx"));
try {
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select name, password, title, memo from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
name = rs.getString(1);
password = rs.getString(2);
title = rs.getString(3);
memo = rs.getString(4);
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException e) {
out.println( e.toString() );
}
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
<script language = "javascript"> // 자바 스크립트 시작
function writeCheck() {
var form = document.modifyform;
if( !form.name.value ) { // form 에 있는 name 값이 없을 때
alert( "이름을 적어주세요" ); // 경고창 띄움
form.name.focus(); // form 에 있는 name 위치로 이동
return;
}
if( !form.password.value ) {
alert( "비밀번호를 적어주세요" );
form.password.focus();
return;
}
if( !form.title.value ) {
alert( "제목을 적어주세요" );
form.title.focus();
return;
}
if( !form.memo.value ) {
alert( "내용을 적어주세요" );
form.memo.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=modifyform method="post" action="modify_ok.jsp">
<input type="hidden" name="idx" vaule="<%=idx%>">
<table width="100%">
<tr>
<td align="center">제목</td>
<td><input name="title" size="50" maxlength="100" vaule="<%=title%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">이름</td>
<td><input name="name" size="50" maxlength="50" vaule="<%=name%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">비밀번호</td>
<td><input name="password" size="50" maxlength="50" vaule="<%=passowrd%>"></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center">내용</td>
<td><textarea name="memo" cols="50" rows="13"><%=memo%></textarea></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr height="1" bgcolor="#82B5DF"><td colspan="2"></td></tr>
<tr align="center">
<td colspan="2">
<input type=button value="수정" OnClick="javascript:modifyCheck();">
<input type=button value="취소" OnClick="javascript:history.back(-1)">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
[ modify_ok.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
request.setCharacterEncoding("utf-8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
try{
request.setCharacterEncoding("utf-8");
int idx = Integer.parseInt(request.getParameter("idx"));
String title = request.getParameter("title");
String memo = request.getParameter("memo");
String passw = request.getParameter("password");
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select password from board wherer idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
password = rs.getString(1);
}
if(password.equals(passw)) {
sql = "update board set title='" + title+ "' , memo='"+ memo +"' where idx=" + idx;
stmt.executeUpdate(sql);
%>
<script language=javascript>
self.window.alert("글이 수정되었습니다.");
location.href="view.jsp?idx=<%=idx%>";
</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/9
댓글목록
등록된 댓글이 없습니다.