반응형
검색기능을 더한 게시판을 Model1으로 해서 구현하고 여기에 view1안에는 이전글, 다음글 기능을 추가하는 게시판을 만들었다.
ModelEx01.search1.BoardDAO
package search1;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
// 각 페이지당 할일
public class BoardDAO {
// jsp 처리할 일을 메소드화
// jsp 페이지와 1 : 1
private DataSource datasource = null;
public BoardDAO() {
// 데이터 소스를 얻어 냄
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
this.datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
} catch (NamingException e) {
System.out.println("[에러] : " + e.getMessage());
}
}
public void boardWrite() {
// 할 일 없음
}
public int boardWriteOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
int flag = 1;
try {
conn = datasource.getConnection();
String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSubject());
pstmt.setString(2, to.getWriter());
pstmt.setString(3, to.getMail());
pstmt.setString(4, to.getPassword());
pstmt.setString(5, to.getContent());
pstmt.setString(6, to.getWip());
int result = pstmt.executeUpdate();
if(result == 1) {
flag = 0;
}
} catch(SQLException e) {
System.out.println("[에러] " + e.getMessage());
} finally {
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return flag;
}
public BoardListTO boardList(BoardListTO listTO) { // 20180725
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int cpage = listTO.getCpage(); // 20180725
int recordPerPage = listTO.getrecordPerPage(); // 20180725
int blockPerPage = listTO.getblockPerPage(); // 20180725
String searchKey = listTO.getSearchKey();
String searchWord = listTO.getSearchWord();
//ArrayList<BoardTO> lists = new ArrayList<>(); // 20180725
try {
conn = datasource.getConnection();
if (searchKey.equals("subject")) {
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, "
+ "hit, trunc(sysdate-wdate) wgap from board1 "
+ "where subject like '%" + searchWord + "%' order by seq desc";
pstmt = conn.prepareStatement(sql);
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
} else if (searchKey.equals("content")) {
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, "
+ "hit, trunc(sysdate-wdate) wgap from board1 "
+ "where content like '%" + searchWord + "%' order by seq desc";
pstmt = conn.prepareStatement(sql);
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
} else if (searchKey.equals("writer")) {
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, "
+ "hit, trunc(sysdate-wdate) wgap from board1 "
+ "where writer like '%" + searchWord + "%' order by seq desc";
pstmt = conn.prepareStatement(sql);
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
} else {
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, "
+ "hit, trunc(sysdate-wdate) wgap from board1 order by seq desc";
pstmt = conn.prepareStatement(sql);
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
}
rs = pstmt.executeQuery();
// 커서를 맨 마지막행으로 이동
rs.last();
// 데이터 개수가 나옴
listTO.setTotalRecord(rs.getRow()); // 20180725
rs.beforeFirst();
listTO.setTotalPage(((listTO.getTotalRecord() - 1)/recordPerPage) + 1); // 20180725
int skip = (cpage - 1) * recordPerPage; // 20180725
if(skip != 0) rs.absolute(skip); // 20180725
ArrayList<BoardTO> boardLists = new ArrayList<>(); // 20180725
//while(rs.next()) { // 20180725
for(int i=0; i<recordPerPage && rs.next(); i++) { // 20180725
BoardTO to = new BoardTO();
to.setSeq(rs.getString("seq"));
to.setSubject(rs.getString("subject"));
to.setWriter(rs.getString("writer"));
to.setWdate(rs.getString("wdate"));
to.setHit(rs.getString("hit"));
to.setWgap(rs.getInt("wgap"));
//lists.add(to); // 20180725
boardLists.add(to); // 20180725
}
listTO.setBoardLists(boardLists); // 20180725
listTO.setStartBlock(((cpage -1)/blockPerPage)*blockPerPage + 1); // 20180725
listTO.setEndBlock(((cpage -1)/blockPerPage)*blockPerPage + blockPerPage); // 20180725
if(listTO.getEndBlock() >= listTO.getTotalPage()) { // 20180725
listTO.setEndBlock(listTO.getTotalPage()); // 2018turn flag;
} mt.close();
rs.close();
// 이전글
if(searchWord.equals("")) {
sql = "select seq, subject from board1 where seq=(select min(seq) from board1 where seq > ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
} else {
sql = "select seq, subject from board1 where seq=(select min(seq) from board1 where '%"+ searchKey + "%' like ? and seq > ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSearchWord());
pstmt.setString(2, to.getSeq());
}
rs = pstmt.executeQuery();
if(rs.next()) {
to.setAfterSeq(rs.getString("seq"));
to.setAfterSubject(rs.getString("subject"));
}
pstmt.close();
rs.close();
/*
if(preSeq.equals(preSeq)) {
pstmt.executeUpdate();
// 이전글
sql = "select seq, subject from board1 where seq=(select max(seq) from board1 where seq < ?)";
//sql = "select * from (select seq, subject,"
// + "lag(seq,1) over(order by seq) pre_seq,"
// + "lag(sbuject, 1, '') over(order by seq) pre_subject,"
// + "from board1"
// + ")";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setPreSeq(rs.getString("seq"));
}
}
if(afterSeq.equals(afterSeq)) {
// 다음글
sql = "select seq, subject from board1 where seq=(select min(seq) from board1 where seq > ?)";
//sql = "select * from (select seq, subject,"
// + "lead(seq, 1) over(order by seq) next_seq,"
// + "lead(subject, 1, '') over(order by seq) next_subject,"
// + "from board1"
// + ")";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setAfterSeq(rs.getString("seq"));
}
}
*/
} catch(SQLException e) {
System.out.println("[에러] " + e.getMessage());
} finally {
if(rs != null) try {rs.close();} catch(SQLException e) {};
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return to;
}
public int boardModify(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int flag = 2;
try {
conn = datasource.getConnection();
String sql = "select writer, subject, content, mail from board1 where seq = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setWriter(rs.getString("writer"));
to.setSubject(rs.getString("subject"));
to.setContent(rs.getString("content") == null ? "" : rs.getString("content").replaceAll("\n", "<br />"));
to.setMail(rs.getString("mail"));
int result = pstmt.executeUpdate();
if(result == 1) {
// 정상
flag = 0;
} else if (result == 0) {
// 비밀번호 오류
flag = 1;
}
}
} catch(SQLException e) {
System.out.println("[에러] " + e.getMessage());
} finally {
if(rs != null) try {rs.close();} catch(SQLException e) {};
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return flag;
}
public int boardModifyOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
int flag = 2;
try {
conn = datasource.getConnection();
String sql = "update board1 set subject=?, mail=?, password=?, content=? where seq = ? and password = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSubject());
pstmt.setString(2, to.getMail());
pstmt.setString(3, to.getPassword());
pstmt.setString(4, to.getContent());
pstmt.setString(5, to.getSeq());
pstmt.setString(6, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 1) {
// 정상
flag = 0;
} else if (result == 0) {
// 비밀번호 오류
flag = 1;
}
} catch(SQLException e) {
System.out.println("[에러] " + e.getMessage());
} finally {
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return flag;
}
public void boardDelete() {
// 할 일 없음
}
public int boardDeleteOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
int flag = 2;
try {
conn = datasource.getConnection();
String sql = "delete from board1 where seq = ? and password = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.setString(2, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 1) {
// 정상
flag = 0;
} else if (result == 0) {
// 비밀번호 오류
flag = 1;
}
} catch(SQLException e) {
System.out.println("[에러] " + e.getMessage());
} finally {
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return flag;
}
}
ModelEx01.search1.BoardListTO
package search1;
import java.util.ArrayList;
public class BoardListTO {
private int cpage;
private int recordPerPage;
private int blockPerPage;
private int totalPage;
private int totalRecord;
private int startBlock;
private int endBlock;
private String searchKey;
private String searchWord;
private ArrayList<BoardTO> boardLists;
public BoardListTO() {
this.cpage = 1;
this.recordPerPage = 10;
this.blockPerPage = 5;
this.totalPage = 1;
this.totalRecord = 0;
this.searchWord = "";
this.searchKey = "";
}
public int getCpage() {
return cpage;
}
public void setCpage(int cpage) {
this.cpage = cpage;
}
public int getrecordPerPage() {
return recordPerPage;
}
public void setrecordPerPage(int recordPerPage) {
this.recordPerPage = recordPerPage;
}
public int getblockPerPage() {
return blockPerPage;
}
public void setblockPerPage(int blockPerPage) {
this.blockPerPage = blockPerPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public int getStartBlock() {
return startBlock;
}
public void setStartBlock(int startBlock) {
this.startBlock = startBlock;
}
public int getEndBlock() {
return endBlock;
}
public void setEndBlock(int endBlock) {
this.endBlock = endBlock;
}
public ArrayList<BoardTO> getBoardLists() {
return boardLists;
}
public void setBoardLists(ArrayList<BoardTO> boardLists) {
this.boardLists = boardLists;
}
public String getSearchWord() {
return searchWord;
}
public void setSearchWord(String searchWord) {
this.searchWord = searchWord;
}
public String getSearchKey() {
return searchKey;
}
public void setSearchKey(String searchKey) {
this.searchKey = searchKey;
}
}
ModelEx01.search1.BoardTO
package search1;
// 데이터
public class BoardTO {
// data - table / select(list + view)
private String seq;
private String subject;
private String writer;
private String mail;
private String[] email;
private String password;
private String content;
private String hit;
private String wip;
private String wdate;
private int wgap;
private String cpage;
private String searchKey;
private String searchWord;
private String preSeq;
private String preSubject;
private String afterSeq;
private String afterSubject;
public BoardTO() {
this.preSeq = "";
this.preSubject = "";
this.afterSeq = "";
this.afterSubject = "";
this.searchKey = "";
this.searchWord = "";
}
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getHit() {
return hit;
}
public void setHit(String hit) {
this.hit = hit;
}
public String getWip() {
return wip;
}
public void setWip(String wip) {
this.wip = wip;
}
public String getWdate() {
return wdate;
}
public void setWdate(String wdate) {
this.wdate = wdate;
}
public int getWgap() {
return wgap;
}
public void setWgap(int wgap) {
this.wgap = wgap;
}
public String[] getEmail() {
return email;
}
public void setEmail(String[] email) {
this.email = email;
}
public String getCpage() {
return cpage;
}
public void setCpage(String cpage) {
this.cpage = cpage;
}
public String getSearchWord() {
return searchWord;
}
public void setSearchWord(String searchWord) {
this.searchWord = searchWord;
}
public String getSearchKey() {
return searchKey;
}
public void setSearchKey(String searchKey) {
this.searchKey = searchKey;
}
public String getPreSeq() {
return preSeq;
}
public void setPreSeq(String preSeq) {
this.preSeq = preSeq;
}
public String getAfterSeq() {
return afterSeq;
}
public void setAfterSeq(String afterSeq) {
this.afterSeq = afterSeq;
}
public String getPreSubject() {
return preSubject;
}
public void setPreSubject(String preSubject) {
this.preSubject = preSubject;
}
public String getAfterSubject() {
return afterSubject;
}
public void setAfterSubject(String afterSubject) {
this.afterSubject = afterSubject;
}
}
ModelEx01.search1.board_list1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- Java 전처리 -->
<%@ page import="search1.BoardTO" %> <!-- 20180725 -->
<%@ page import="search1.BoardListTO" %> <!-- 20180725 -->
<%@ page import="search1.BoardDAO" %> <!-- 20180725 -->
<%@ page import="java.util.ArrayList" %> <!-- 20180725 -->
<%
request.setCharacterEncoding("utf-8");
int cpage = 1;
if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
cpage = Integer.parseInt(request.getParameter("cpage"));
}
String searchWord = "";
if(request.getParameter("searchWord") != null && !request.getParameter("searchWord").equals("")) {
searchWord = request.getParameter("searchWord");
}
String searchKey = "";
if(request.getParameter("searchKey") != null && !request.getParameter("searchKey").equals("")) {
searchKey = request.getParameter("searchKey");
}
BoardListTO listTO = new BoardListTO(); // 20180725
listTO.setCpage(cpage); // 20180725
listTO.setSearchKey(searchKey);
listTO.setSearchWord(searchWord);
BoardDAO dao = new BoardDAO(); // 20180725
listTO = dao.boardList(listTO); // 20180725
//int recordPerPage = 10; // 20180725
int totalRecord = listTO.getTotalRecord(); // 20180725
int totalPage = listTO.getTotalPage(); // 20180725
int blockPerPage = listTO.getblockPerPage(); // 한 페이지당 5개 // 20180725
int startBlock = listTO.getStartBlock(); // 20180725
int endBlock = listTO.getEndBlock(); // 20180725
//Connection conn = null; // 20180725
//PreparedStatement pstmt = null; // 20180725
//ResultSet rs = null; // 20180725
ArrayList<BoardTO> boardlLists = listTO.getBoardLists(); // 20180725
StringBuffer sb = new StringBuffer();
for(BoardTO to : boardlLists) {
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String wdate = to.getWdate();
String hit = to.getHit();
int wgap = to.getWgap();
sb.append("<tr>");
sb.append(" <td> </td>");
//sb.append(" <td>").append(rs.getString("seq")).append("</td>");
sb.append(" <td>" + seq + "</td>");
if(wgap == 0 ) {
sb.append(" <option value='writer'>이름</option>");
}
%>
</select>
<input type="text" name="searchWord" value="" class="board_input" />
<button type='button' class="btn_search btn_txt" id="submit1">검색</button>
</div>
<!--//검색-->
</div>
</form>
<!--게시판-->
<div class="board">
<table>
<tr>
<th width="3%"> </th>
<th width="5%">번호</th>
<th>제목</th>
<th width="10%">글쓴이</th>
<th width="17%">등록일</th>
<th width="5%">조회</th>
<th width="3%"> </th>
</tr>
<tr>
<!-- 시작 -->
<%= sb %>
<!-- 끝 -->
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>&searchWord=<%=searchWord %>'">목록</button>
</div>
<div class="align_right">
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?cpage=<%=cpage %>&searchWord=<%=searchWord %>'">쓰기</button>
</div>
</div>
<!--//게시판-->
<!--페이지넘버-->
<div class="paginate_regular">
<div class="board_pagetab" align="absmiddle">
<%
//int startBlock = ((cpage -1) / blockPerPage)*blockPerPage + 1;
//int endBlock = ((cpage -1) / blockPerPage)*blockPerPage + blockPerPage;
if(endBlock >= totalPage) {
endBlock = totalPage;
}
%>
<%
if(startBlock == 1) {
out.println("<span class='on'><<</span>");
} else {
out.println("<span class='off'><a href='./board_list1.jsp?cpage=" + (startBlock - blockPerPage) + "&searchWord=" + searchWord + "'><< </a></span>");
out.println(" ");
}
%>
<%
if(cpage == 1) {
out.println("<span class='on'><</span>");
} else {
out.println("<span class='off'><a href='./board_list1.jsp?cpage=" + (cpage-1) + "&searchWord=" + searchWord + "'>< </a></span>");
out.println(" ");
}
%>
<%
for(int i=startBlock; i<=endBlock; i++) {
if(cpage == i) {
out.println("<span class='on'>[ " + i + " ]</span>");
} else {
out.println("<span class='off'><a href='./board_list1.jsp?cpage=" + i + "&searchWord=" + searchWord + "'>" + i + "</a></span>");
}
}
%>
<%
if(cpage == totalPage) {
out.println("<span class='on'>></span>");
} else {
out.println("<span class='off'><a href='./board_list1.jsp?cpage=" + (cpage+1) + "&searchWord=" + searchWord + "'>> </a></span>");
out.println(" ");
}
%>
<%
if(endBlock == totalPage) {
out.println("<span class='on'>>></span>");
} else {
out.println("<span class='off'><a href='./board_list1.jsp?cpage=" + (startBlock + blockPerPage) + "&searchWord=" + searchWord + "'>>> </a></span>");
out.println(" ");
}
%>
</div>
</div>
<!--//페이지넘버-->
</div>
</div>
<!--//하단 디자인 -->
</body>
</html>
ModelEx01.search1.board_view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO" %>
<%@ page import="search1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
int cpage = 1;
if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
cpage = Integer.parseInt(request.getParameter("cpage"));
}
String seq = request.getParameter("seq");
String searchKey = request.getParameter("searchKey");
String searchWord = request.getParameter("searchWord");
int seq_p = Integer.parseInt(seq);
BoardTO to = new BoardTO();
to.setSeq(seq);
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
String subject = to.getSubject();
String writer = to.getWriter();
String wdate = to.getWdate();
String hit = to.getHit();
String content = to.getContent();
String mail = to.getMail();
String preSeq = to.getPreSeq();
String preSubject = to.getPreSubject();
String afterSeq = to.getAfterSeq();
String afterSubject = to.getAfterSubject();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_view.css">
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<div class="contents_sub">
<!--게시판-->
<div class="board_view">
<table>
<tr>
<th width="10%">제목</th>
<td width="60%"><%= subject %></td>
<th width="10%">등록일</th>
<td width="20%"><%= wdate %></td>
</tr>
<tr>
<th>글쓴이</th>
<td><%= writer %><%= '(' + mail + ')' %></td>
<th>조회</th>
<td><%= hit %></td>
</tr>
<tr>
<td colspan="4" height="200" valign="top" style="padding: 20px; line-height: 160%"><%= content %></td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>&searchKey=<%=searchKey %>&searchWord=<%=searchWord %>'">목록</button>
</div>
<div class="align_right">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?cpage=<%=cpage %>&seq=<%=seq %>&searchKey=<%=searchKey %>&searchWord=<%=searchWord %>'">수정</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?cpage=<%=cpage %>&seq=<%=seq %>&searchKey=<%=searchKey %>&searchWord=<%=searchWord %>'">삭제</button>
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?cpage=<%=cpage %>&searchKey=<%=searchKey %>&searchWord=<%=searchWord %>'">쓰기</button>
</div>
</div>
<!-- 이전글 / 다음글 -->
<div class="next_data_area">
<%
if(afterSeq == "") {
out.println("<span class='b'>다음글 |</span> <a href='board_view1.jsp?searchkey=" + searchKey + "&searchWord=" + searchWord + "&seq=" + seq + "&cpage=" + cpage + "'>다음글이 없습니다.</a>");
} else {
out.println("<span class='b'>다음글 |</span> <a href='board_view1.jsp?searchkey=" + searchKey + "&searchWord=" + searchWord + "&seq=" + afterSeq + "&cpage=" + cpage + "'>"+ afterSubject + "</a>");
}
%>
</div>
<div class="prev_data_area">
<%
if(preSeq == "") {
out.println("<span class='b'>이전글 |</span> <a href='board_view1.jsp?searchkey=" + searchKey + "&searchWord=" + searchWord + "&seq=" + seq + "&cpage=" + cpage + "'>이전글이 없습니다.</a>");
} else {
out.println("<span class='b'>이전글 |</span> <a href='board_view1.jsp?searchkey=" + searchKey + "&searchWord=" + searchWord + "&seq=" + preSeq + "&cpage=" + cpage + "'>"+ preSubject + "</a>");
}
%>
</div>
<!-- //이전글 / 다음글 -->
<!--//게시판-->
</div>
</div>
<!-- 하단 디자인 -->
</body>
</html>
ModelEx01.search1.board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
String searchWord = request.getParameter("searchWord");
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
//alert('click');
if(document.frm.info.checked == false) {
alert('동의하셔야 합니다.');
return;
}
if(document.frm.writer.value.trim() == "") {
alert('이름을 입력하셔야 합니다.');
return;
}
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
if(document.frm.subject.value.trim() == "") {
alert('제목을 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_write1_ok.jsp" method="post" name="frm">
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3"><textarea name="content" class="board_editor_area"></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
</tr>
</table>
<table>
<tr>
<br />
<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
<div style="padding-left:10px;">
<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
</div>
</div>
<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
</div>
</td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>&searchWord=<%=searchWord %>'">목록</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
ModelEx01.search1.board_write1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO"%>
<%@ page import="search1.BoardDAO"%>
<%
request.setCharacterEncoding("utf-8");
String subject = request.getParameter("subject");
String writer = request.getParameter("writer");
String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
String password = request.getParameter("password");
String content = request.getParameter("content");
String wip = request.getRemoteAddr();
BoardTO to = new BoardTO();
to.setSubject(subject);
to.setWriter(writer);
to.setMail(mail);
to.setPassword(password);
to.setContent(content);
to.setWip(wip);
BoardDAO dao = new BoardDAO();
int flag = dao.boardWriteOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글쓰기에 성공했습니다.');");
out.println("location.href='./board_list1.jsp';");
} else if(flag == 1) {
out.println("alert('글쓰기에 실패했습니다.');");
out.println("history.back();");
}
out.println("</script>");
%>
ModelEx01.search1.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO" %>
<%@ page import="search1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
String seq = request.getParameter("seq");
String cpage = request.getParameter("cpage");
String searchWord = request.getParameter("searchWord");
BoardTO to = new BoardTO();
to.setSeq(seq);
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
String subject = to.getSubject();
String writer = to.getWriter();
String content = to.getContent();
String mail[] = to.getMail().split("@");
if(mail.length == 0) {
mail = new String[] {"", ""};
}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.writer.value.trim() == "") {
alert('이름을 입력하셔야 합니다.');
return;
}
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
if(document.frm.subject.value.trim() == "") {
alert('제목을 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_modify1_ok.jsp" method="post" name="frm">
<input type="hidden" name="seq" value="<%=seq %>" />
<input type="hidden" name="cpage" value="<%=cpage %>" />
<input type="hidden" name="searchWord" value="<%=searchWord %>" />
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3"><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><input type="text" name="mail1" value="<%=mail[0] %>" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="<%=mail[1] %>" class="board_view_input_mail"/></td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>&searchWord=<%=searchWord %>'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?cpage=<%=cpage %>&seq=<%=seq %>&searchWord=<%=searchWord %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">수정</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
ModelEx01.search1.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO" %>
<%@ page import="search1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
String seq = request.getParameter("seq");
String subject = request.getParameter("subject");
String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
String password = request.getParameter("password");
String content = request.getParameter("content");
String wip = request.getRemoteAddr();
String cpage = request.getParameter("cpage");
String searchWord = request.getParameter("searchWord");
BoardTO to = new BoardTO();
to.setSubject(subject);
to.setMail(mail);
to.setPassword(password);
to.setContent(content);
to.setSeq(seq);
to.setCpage(cpage);
BoardDAO dao = new BoardDAO();
int flag = dao.boardModifyOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글 수정에 성공했습니다.');");
out.println("location.href='./board_list1.jsp?cpage=" + cpage + "&seq=" + seq + "&searchWord=" + searchWord + "'");
} else if(flag == 1) {
out.println("alert('비밀번호 오류입니다.');");
out.println("history.back();");
} else if(flag == 2) {
out.println("alert('글 수정에 실패했습니다.');");
out.println("history.back();");
}
out.println("</script>");
%>
ModelEx01.search1.board_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO" %> <!-- 20180725 -->
<%@ page import="search1.BoardDAO" %> <!-- 20180725 -->
<%
request.setCharacterEncoding("utf-8");
String seq = request.getParameter("seq");
String cpage = request.getParameter("cpage");
String searchWord = request.getParameter("searchWord");
BoardTO to = new BoardTO();
to.setSeq(seq);
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
String subject = to.getSubject();
String writer = to.getWriter();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_delete1_ok.jsp" method="post" name="frm">
<input type="hidden" name="seq" value="<%=seq %>" /> <!-- delete할 때 seq를 받아오기 위해 hidden으로해서 작성 / 브라우저에서 소스보기 하면 값 확인가능 -->
<input type="hidden" name="cpage" value="<%=cpage %>" />
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%= writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%= subject %>" class="board_view_input" readonly/></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>&searchWord=<%=searchWord %>'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?cpage=<%=cpage %>&seq=<%=seq %>&searchWord=<%=searchWord %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">삭제</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
ModelEx01.search1.board_delete1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="search1.BoardTO" %> <!-- 20180725 -->
<%@ page import="search1.BoardDAO" %> <!-- 20180725 -->
<%
request.setCharacterEncoding("utf-8");
String seq = request.getParameter("seq");
String password = request.getParameter("password");
String searchWord = request.getParameter("searchWord");
BoardTO to = new BoardTO();
to.setSeq(seq);
to.setPassword(password);
BoardDAO dao = new BoardDAO();
int flag = dao.boardDeleteOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글 삭제에 성공했습니다.');");
out.println("location.href='./board_list1.jsp?seq=" + seq + "&searchWord=" + searchWord + "'");
} else if(flag == 1) {
out.println("alert('비밀번호 오류입니다.');");
out.println("history.back();");
} else if(flag == 2) {
out.println("alert('글 삭제에 실패했습니다.');");
out.println("history.back();");
}
out.println("</script>");
%>
반응형
'Web & Mobile > JSP' 카테고리의 다른 글
Lecture 53 - JSP(11) 페이지 모듈화, 요청 흐름 제어, Include, Cookie, Login, Logout (0) | 2019.05.30 |
---|---|
Lecture 52 - JSP(10) Model1 기반 게시판 파일 업로드 기능 구현 (0) | 2019.05.29 |
Lecture 50 - JSP(8) 모델1 기반 게시판 BoardTO, BoardDAO, 답글쓰기 (0) | 2019.05.27 |
Lecture 49 - JSP(7) 페이지 수를 나타내는 Model1 기반 게시판 (0) | 2019.05.24 |
Lecture 48 - JSP(6) 필수요소이해, 리다이렉트, Session, Application, Buffer, pageContext, Model1기법 게시판 (0) | 2019.05.23 |
댓글