board.QnaDTO
board.QnaDAO
1.새글입력 메서드명 : setContent()
글쓰기 : writeForm.jsp
답글쓰기 : rewriteForm.jsp
글리스트 : listView.jsp
뷰페이지 : contentView.jsp
table : qnaBoard
글번호 : num (primary key)
글제목 : title
글내용 : content
원본글 : ref(원본글이면 원본글의 num, 답변글이면,? 원본글의 num?)
답글순서 : step ( 최신글이면 1, ++ )
들여쓰기 : depth(원본글의 답변이면 1, 답변글의 답변글이면 2)
******************************************************************
Q&A 테이블
create table qnaboard(
num number(6) primary key,
title varchar2(2000),
content varchar2(3000),
ref number(6),
step numbeR(6),
depth number(6)
)
******************************************************************
QnaDTO.java
package board;
public class QnaDTO {
private int num;
private String title;
private String content;
private int ref;
private int step;
private int depth;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getRef() {
return ref;
}
public void setRef(int ref) {
this.ref = ref;
}
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
}
******************************************************************
******************************************************************
writeForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
원본글쓰기 폼
<form action="writePro.jsp" method="post">
<input type="text" name="title"><br>
<textarea rows="20" cols="20" name="content"></textarea><br>
<input type="submit" value="등록">
</form>
</body>
</html>
******************************************************************
writePro.jsp
<%@page import="board.QnaDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="qd" class="board.QnaDTO" />
<jsp:setProperty property="*" name="qd"/>
<%
QnaDAO qa = new QnaDAO();
int result = qa.setContent(qd);
if(result>0){
%>
<h2>글쓰기 성공</h2>
<a href="#">리스트 보기</a>
<% }else{ %>
<h2>글쓰기 실패</h2>
<a href="./qnaWrite.jsp">글쓰기</a>
<% } %>
</body>
</html>
******************************************************************
listView.jsp
<%@page import="board.QnaDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="board.QnaDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int curpage = Integer.parseInt(request.getParameter("curpage"));
QnaDAO qdao = new QnaDAO();
ArrayList<QnaDTO> ar = qdao.getList(curpage);
int total = qdao.getCount();
if(total%10==0){
total = total/10;
}else{
total = (total/10)+1;
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>번호</td><td>제목</td>
</tr>
<%
for(int i=0 ; i <ar.size() ; i++){
%>
<tr>
<td><%=ar.get(i).getNum() %></td>
<td><%=ar.get(i).getTitle() %></td>
</tr>
<%} %>
<%
for(int i=1 ; i<=total ; i++){%>
<a href="listView.jsp?curpage=<%=i %>"><%=i %></a>
<% }%>
</table>
</body>
</html>
******************************************************************
답글 들여쓰기 쿼리문
insert into qnaboard values(1,'test','test',1,0,0)
insert into qnaboard values(2,'test2','test2',2,0,0)
insert into qnaboard values(3,'retest' ,'retest',1,1,1)
insert into qnaboard values(4,'re2test','re2test',1,1,1)
insert into qnaboard values(5,'re3test','re3test',1,1,1)
update qnaboard set step=step+1 where ref=1 and step>0;
select * from qnaboard
select * from qnaboard order by ref desc;
select * from qnaboard order by step asc;
select * from qnaboard order by ref desc, step asc
******************************************************************
parameter 받아오는 방법
1. get방식
2. useBean 액션태그 사용
******************************************************************
'프로그래밍, 통계학 > JSP' 카테고리의 다른 글
[54일차]2015.09.22.화,게시판실습 (0) | 2015.09.22 |
---|---|
[53일차]2015.09.21.월,답글 들여쓰기 설계 (0) | 2015.09.21 |
[52일차]2015.09.19.금, ojdbc6 (0) | 2015.09.18 |
[51일차]2015.09.17, 결석 (0) | 2015.09.18 |
[50일차]2015.09.16.수, 기획서작성, 작업시작 (0) | 2015.09.16 |