저번 포스트에서 만들었던 list.jsp 파일을 연다 .
상세페이지를 구하는 페이지를 작성 한다.
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>게시판</title> </head> <body> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr height="5"><td width="5"></td></tr> <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 width="73">번호</td> <td width="379">제목</td> <td width="73">작성자</td> <td width="164">작성일</td> <td width="58">조회수</td> <td width="7"><img src="img/table_right.gif" width="5" height="30" /></td> </tr> <tr height="25" align="center"> </tr> <tr height="1" bgcolor="#D2D2D2"><td colspan="6"></td></tr> <tr height="1" bgcolor="#82B5DF"><td colspan="6" width="752"></td></tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr><td colspan="4" height="5"></td></tr> <tr align="center"> <td><input type=button value="글쓰기"></td> </tr> </table> </body> </html> |
저희가 사용할 게시판의 디자인양식입니다.
중간에 보시면 img/table_mid.gif 이런게 보이실겁니다.
이미지 파일을 사용하기위해 WebContent폴더에 img폴더를 하나 생성합니다.
<-- table_left.gif
<--table_mid.gif
<--table_right.gif
이 이미지들은
판다의 이상한 블로그(http://ssppmm.tistory.com/) 에서
참고하고 이미지파일도 사용했습니다.
그리고 이제 실행을 시켜보기 위해
완료화면
이제부터 리스트 출력을 위해 데이터베이스를 설정해야한다.
1. mysql 홈페이지에서 5.x 버젼을 다운로드 후 적절한 경로에 압축을 풀고 필요하다면 환경변수를 설정해준다.
2. mysql 홈페이지에서 workbench를 다운로드 후 실행
3. root 계정으로 접속하여 다음과같은 쿼리문을 실행
create user admin identified by '1234'; create database board default character set utf8 collate utf8_general_ci; grant all privileges on *.* to admin identified by '1234' with grant option; flush privileges; |
계정과 데이터베이스가 만들어졌다.
4. 방금 만들었던 계정으로 mysql에 접속한다.
5. 테이블을 만들어준다.
use board; create table board(
idx int(10) not null auto_increment , title varchar(40) not null default '', content varchar(400) not null default '', writer varchar(100) not null default '', wdate timestamp default current_timestamp, udate timestamp null, bpass varchar(32) not null default '', grp int(10) not null default 0, seq int(10) not null default 0, lvl int(10) not null default 0, hit int(10) not null default 0, primary key (idx) ); |
6. 이클립스에서 3가지 클래스를 생성한다.
- BoardOrder 인터페이스
- Board 데이터를 담는 클래스
- BoardDao BoardDao를 상속받아 명령을 수행
7. Board
테이블 생성시 사용한 변수를 복사하여 getter & setter 형태로 사용하도록 만든다.
8. BoardOrder 과 Dao 클래스를 작성한다.
9. jsp 부분을 작성한다.
<%@ page import = "java.sql.*"%> // sql문을 사용하기 위해 import시킵니다. |
기존 list.jsp에 아래와 같은 내용을 추가
<% if(total==0) { // total 즉, 자료가 없다면 %> <tr align="center" bgcolor="#FFFFFF" height="30"> <td colspan="6">등록된 글이 없습니다.</td> </tr> <% } else { // total이 0이 아닌 즉 자료가 1개이상 있다면
while(rs.next()) { // while이라는 반복문으로 자료를 찾습니다. rs.next()는 다음라인으 로 커서 이동 int idx = rs.getInt(1); // 1은 첫번째 즉 num값을 idx라는 변수에 대입 String name = rs.getString(2); // name String title = rs.getString(3); // title String time = rs.getString(4); // time int hit = rs.getInt(5); // hit
%> <tr height="25" align="center"> <td> </td> <td><%=idx %></td> <td align="left"><%=title %></td> <td align="center"><%=name %></td> <td align="center"><%=time %></td> <td align="center"><%=hit %></td> <td> </td> </tr> <tr height="1" bgcolor="#D2D2D2"><td colspan="6"></td></tr> <% } } rs.close(); //rs객체 반환 stmt.close(); // stmt객체 반환 conn.close(); // conn객체 반환 } catch(SQLException e) { out.println( e.toString() ); //에러 날경우 에러출력 } %>
|
'Programming > Web _ jsp' 카테고리의 다른 글
javascript window.laod function($) 로딩 순서 (0) | 2018.08.10 |
---|---|
[jsp_struts]Struts 기본원리 (0) | 2018.05.23 |
[Jsp+Mysql] 게시판 만들기 -1- 프로젝트 세팅 (0) | 2018.05.22 |
답변형 게시판-답글 원리 (0) | 2018.05.20 |
[Struts] 스트럿츠의 기본형태 (0) | 2018.05.15 |