JSP 게시판 만들기 - 내용
페이지 정보
본문
[ view.jsp ]
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
int idx = Integer.parseInt(request.getParameter("idx"));
try {
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select name, title, memo, time, hit from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
String name = rs.getString(1);
String title = rs.getString(2);
String memo = rs.getString(3);
String time = rs.getString(4);
int hit = rs.getInt(5);
hit++;
sql = "update board SET hit=" + hit + " where idx=" +idx;
stmt.executeUpdate(sql);
rs.close();
stmt.close();
conn.close();
}
}catch(SQLException e) {
}
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
</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>
<table width="100%">
<tr>
<td align="center" width="76">글번호</td>
<td width="319"><%=idx%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">조회수</td>
<td><%=hit%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">이름</td>
<td><%=name%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">작성일</td>
<td><%=time%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">제목</td>
<td><%=title%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td colspan="2" height="200"><%=memo %></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 width="0"> </td>
<td colspan="2" width="399">
<input type=button value="글쓰기" onClick="window.location='write.jsp'">
<input type=button value="답글" onClick="window.location='reply.jsp?idx=<%=idx%>'">
<input type=button value="목록" onClick="window.location='list.jsp'">
<input type=button value="수정" onClick="window.location='modify.jsp?idx=<%=idx%>'">
<input type=button value="삭제" onClick="window.location='delete.jsp?idx=<%=idx%>'">
</td>
<td width="0"> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
출처
http://seinarin.tistory.com/7
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:디비네임";
String id = "디비아이디";
String pass = "디비패스워드";
int idx = Integer.parseInt(request.getParameter("idx"));
try {
Connection conn = DriverManager.getConnection(url,id,pass);
Statement stmt = conn.createStatement();
String sql = "select name, title, memo, time, hit from board where idx=" + idx;
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
String name = rs.getString(1);
String title = rs.getString(2);
String memo = rs.getString(3);
String time = rs.getString(4);
int hit = rs.getInt(5);
hit++;
sql = "update board SET hit=" + hit + " where idx=" +idx;
stmt.executeUpdate(sql);
rs.close();
stmt.close();
conn.close();
}
}catch(SQLException e) {
}
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>게시판</title>
</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>
<table width="100%">
<tr>
<td align="center" width="76">글번호</td>
<td width="319"><%=idx%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">조회수</td>
<td><%=hit%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">이름</td>
<td><%=name%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">작성일</td>
<td><%=time%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td align="center" width="76">제목</td>
<td><%=title%></td>
</tr>
<tr height="1" bgcolor="#dddddd"><td colspan="2"></td></tr>
<tr>
<td colspan="2" height="200"><%=memo %></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 width="0"> </td>
<td colspan="2" width="399">
<input type=button value="글쓰기" onClick="window.location='write.jsp'">
<input type=button value="답글" onClick="window.location='reply.jsp?idx=<%=idx%>'">
<input type=button value="목록" onClick="window.location='list.jsp'">
<input type=button value="수정" onClick="window.location='modify.jsp?idx=<%=idx%>'">
<input type=button value="삭제" onClick="window.location='delete.jsp?idx=<%=idx%>'">
</td>
<td width="0"> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
출처
http://seinarin.tistory.com/7
댓글목록
등록된 댓글이 없습니다.