STUDY/programing

JSP 기초 : 게시판 만들기 5. 게시판 DB 생성

NightOwl 2018. 10. 22. 11:42
728x90

1. 게시판 디자인 bbs.jsp




bbs.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ page import="java.io.PrintWriter"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<!-- 뷰포트 -->

<meta name="viewport" content="width=device-width" initial-scale="1">

<!-- 스타일시트 참조  -->

<link rel="stylesheet" href="css/bootstrap.css">

<title>jsp 게시판 웹사이트</title>

</head>

<body>

<%

//로긴한사람이라면 userID라는 변수에 해당 아이디가 담기고 그렇지 않으면 null값

String userID = null;

if (session.getAttribute("userID") != null) {

userID = (String) session.getAttribute("userID");


}

%>



<!-- 네비게이션  -->

<nav class="navbar navbar-default">

<div class="navbar-header">

<button type="button" class="navbar-toggle collapsed"

data-toggle="collapse" data-target="bs-example-navbar-collapse-1"

aria-expaned="false">

<span class="icon-bar"></span> <span class="icon-bar"></span> <span

class="icon-bar"></span>

</button>

<a class="navbar-brand" href="main.jsp">JSP 게시판</a>

</div>

<div class="collapse navbar-collapse"

id="#bs-example-navbar-collapse-1">

<ul class="nav navbar-nav">

<li><a href="main.jsp">메인</a></li>

<li class="active"><a href="bbs.jsp">게시판</a></li>

</ul>



<%

//라긴안된경우

if (userID == null) {

%>

<ul class="nav navbar-nav navbar-right">

<li class="dropdown"><a href="#" class="dropdown-toggle"

data-toggle="dropdown" role="button" aria-haspopup="true"

aria-expanded="false">접속하기<span class="caret"></span></a>

<ul class="dropdown-menu">

<li><a href="login.jsp">로그인</a></li>

<li><a href="join.jsp">회원가입</a></li>

</ul>

</li>

</ul>

<%

} else {

%>

<ul class="nav navbar-nav navbar-right">

<li class="dropdown"><a href="#" class="dropdown-toggle"

data-toggle="dropdown" role="button" aria-haspopup="true"

aria-expanded="false">회원관리<span class="caret"></span></a>

<ul class="dropdown-menu">

<li><a href="logoutAction.jsp">로그아웃</a></li>

</ul>

</li>

</ul>

<%

}

%>

</div>

</nav>

<!-- 게시판 -->

<div class="container">

<div class = "row">

<table class="table table-striped" style="text-align:center; border:1px solid #dddddd"> 

<thead>

<tr>

<th style="background-color: #eeeeee; text-align: center;">번호</th>

<th style="background-color: #eeeeee; text-align: center;">제목</th>

<th style="background-color: #eeeeee; text-align: center;">작성자</th>

<th style="background-color: #eeeeee; text-align: center;">작성일</th>

</tr>

</thead>

<tbody>

<tr>

<td>1</td>

<td>안녕하세요</td>

<td>홍길동</td>

<td>2017-05-04</td>

</tr>

</tbody>

</table>

<a href = "write.jsp" class="btn btn-primary pull-right">글쓰기</a>

</div>

</div>




<!-- 애니매이션 담당 JQUERY -->

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<!-- 부트스트랩 JS  -->

<script src="js/bootstrap.js"></script>


</body>

</html>


 




2. 게시판 DB 생성





mysql> use BBS;

Database changed

mysql> CREATE TABLE BBS (

    -> bbsID INT,

    -> bbsTitle VARCHAR(50),

    -> userID VARCHAR(20),

    -> bbsDate DATETIME,

    -> bbsContent VARCHAR(2048),

    -> bbsAvailable INT,

    -> PRIMARY KEY (bbsID)

    -> ) DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;

Query OK, 0 rows affected (0.03 sec)

 



bbsAvailable : 글 삭제 목적( 1 : 삭제되지 않은 글, 0 : 삭제된 글)


한글 입력을 위해 테이블 생성시

DEFAULT CHARSET=utf8 COLLATE utf8_general_ci; 추가 입력 




3. 게시판 자바 빈즈 생성


[Java Resources] - [src]  bbs 패키지 생성 후

Bbs 자바 빈즈 생성

(하나의 게시글 정보를 만들 수 있는 인스턴스를 만들기 위한 틀)



getters setters 지정





bbs.java


package bbs;


public class Bbs {

private int bbsID;

private String bbsTitle;

private String userID;

private String bbsDate;

private String bbsContent;

private int bbsAvailable;

public int getBbsID() {

return bbsID;

}

public void setBbsID(int bbsID) {

this.bbsID = bbsID;

}

public String getBbsTitle() {

return bbsTitle;

}

public void setBbsTitle(String bbsTitle) {

this.bbsTitle = bbsTitle;

}

public String getUserID() {

return userID;

}

public void setUserID(String userID) {

this.userID = userID;

}

public String getBbsDate() {

return bbsDate;

}

public void setBbsDate(String bbsDate) {

this.bbsDate = bbsDate;

}

public String getBbsContent() {

return bbsContent;

}

public void setBbsContent(String bbsContent) {

this.bbsContent = bbsContent;

}

public int getBbsAvailable() {

return bbsAvailable;

}

public void setBbsAvailable(int bbsAvailable) {

this.bbsAvailable = bbsAvailable;

}


}


 





↘↘ 다음 글 보기


2018/10/23 - [ 컴알못/Web] - JSP 기초 : 게시판 만들기 6. 글 등록 기능


728x90