bbs/list.jsp
페이지 정보
작성자 관리자 작성일 23-03-15 15:22 조회 409 댓글 0본문
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/header.jsp" %>
<%
String code = request.getParameter("code"); //데이타베이스 게시판 테이블명
//검색 관련
String field, search, sql_search;
if(request.getParameter("search") != null && !request.getParameter("search").equals("")){ //검색어가 존재한다면
field = request.getParameter("field");
search = request.getParameter("search");
sql_search = " and "+field+" like '%"+search+"%' "; //sql 구문에 추가할 변수처리
}else{
field = "";
search = "";
sql_search = "";
}
//게시판 타이틀
String bbs_title = "";
if(code.equals("notice")){
bbs_title = "공지게시판";
}else if(code.equals("free")){
bbs_title = "자유게시판";
}else if(code.equals("gallery")){
bbs_title = "갤러리게시판";
}else if(code.equals("qna")){
bbs_title = "QnA게시판";
}
//총 게시물 수 (공지글 제외)
String sql_count="select count(*) from "+code+" where gongji != '1'"+sql_search;
Connection conn_count=DriverManager.getConnection(url, user, password);
Statement stmt_count=conn_count.createStatement();
ResultSet rs_count=stmt_count.executeQuery(sql_count);
int total_record = 0;
if(rs_count.next()){
total_record = rs_count.getInt(1);
}
rs_count.close();
stmt_count.close();
conn_count.close();
//페이징 관련
int page_now = 1;
if(request.getParameter("page_now") != null){
page_now = Integer.parseInt(request.getParameter("page_now")); //현재 페이징 수
}
int num_per_page = 5; //한 페이지당 출력 게시물 수
int page_per_block = 3; //한 블럭당 출력 링크 수
int total_page = (int)Math.ceil(total_record / (double)num_per_page); //총 페이지 수
int first = num_per_page * (page_now - 1); //limit 시작 값
%>
<table width=100% height=50 border=0>
<tr>
<td align=center style="color:#777;font-size:14px;font-weight:bold;">[<%=bbs_title %>]</td>
</tr>
</table>
<center>
<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Total : <%=total_record %></td>
<td align="right">
<form action="list.jsp" method="get">
<input type="hidden" name="code" value="<%=code%>">
<select name="field" style="height:20px;">
<option value='subject' <%if(field.equals("subject")){%>selected<%}%>>제목</option>
<option value='comment' <%if(field.equals("comment")){%>selected<%}%>>내용</option>
<option value='name' <%if(field.equals("name")){%>selected<%}%>>글쓴이</option>
</select>
<input name="search" value="<%=search%>" style="height:16px;">
<button>검색</button>
</form>
</td>
</tr>
</table>
<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#e5ecef" height="30">
<td width="60" align="center"><b>번호</b></td>
<td width="440"><b>제목</b></td>
<td width="100" align="center"><b>글쓴이</b></td>
<td width="100" align="center"><b>날짜</b></td>
</tr>
<%
// 공지글
String sql_top = "select * from "+code+" where gongji = '1' order by uid desc"; // 최신순 정렬
Connection conn_top=DriverManager.getConnection(url, user, password);
Statement stmt_top=conn_top.createStatement();
ResultSet rs_top=stmt_top.executeQuery(sql_top);
while(rs_top.next()){
String uid = rs_top.getString("uid");
String id = rs_top.getString("id");
String subject = rs_top.getString("subject");
String gongji = rs_top.getString("gongji");
String name = rs_top.getString("name");
String signdate = rs_top.getString("signdate");
String file1 = rs_top.getString("file1");
%>
<tr height="26" bgcolor="#fff6fa">
<td align="center"><font color=red>[공지]</font></td>
<td>
<a href="view.jsp?code=<%=code%>&uid=<%=uid%>&field=<%=field%>&search=<%=search%>"><%=subject %></a>
<%if(!file1.equals("")){ //파일첨부%><img src="img/icon_file.gif"><%}%>
</td>
<td align="center"><%=name %></td>
<td align="center"><%=signdate %></td>
</tr>
<tr><td colspan=4 height=1 width=100% bgcolor=#d1dee2></td></tr>
<%
}
rs_top.close();
stmt_top.close();
conn_top.close();
// 일반,비밀글 목록
String sql=" select * from "+code+" where gongji != '1' "+sql_search+" order by uid desc LIMIT "+first+", "+num_per_page; // 최신순 정렬
Connection conn=DriverManager.getConnection(url, user, password);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
String uid = rs.getString("uid");
String id = rs.getString("id");
String subject = rs.getString("subject");
String gongji = rs.getString("gongji");
String name = rs.getString("name");
String signdate = rs.getString("signdate");
String file1 = rs.getString("file1");
//제목 길이 ... 처리
int len_num = subject.length(); //제목 길이
if(len_num > 36){ //길이 비교
subject = subject.substring(0, 36) + " ...";
}else{
subject = subject;
}
//2일전까지 최신글 처리
java.util.Date signdate2, day2;
java.util.Date today = new java.util.Date(); //현재 날짜
java.util.Date day_22 = new java.util.Date(today.getTime() - (long)(1000*60*60*24*2)); //현재 날짜 - 2일
SimpleDateFormat bbb = new SimpleDateFormat("yyyy-MM-dd"); //년-월-일 변경
String day_2 = bbb.format(day_22); //2일전 날짜를 문자열 변수에 대입
day2 = new SimpleDateFormat("yyyy-MM-dd").parse(day_2); //2일전
signdate2 = new SimpleDateFormat("yyyy-MM-dd").parse(signdate); //작성일
%>
<tr height="26">
<td align="center"><%=uid %></td>
<td>
<%if(gongji.equals("3")){ //비밀글 %>
<%if((session_level != null && session_level.equals("10")) || (session_id != null && session_id.equals(id))){ //관리자 or 작성자 %>
<a href="view.jsp?code=<%=code%>&uid=<%=uid%>&field=<%=field%>&search=<%=search%>&page_now=<%=page_now%>"><%=subject %></a>
<%}else{ %>
<%=subject %>
<%} %>
<%}else{ //일반글 %>
<a href="view.jsp?code=<%=code%>&uid=<%=uid%>&field=<%=field%>&search=<%=search%>&page_now=<%=page_now%>"><%=subject %></a>
<%} %>
<%if(signdate2.getTime() >= day2.getTime()){%><img src="img/main_new.gif"><%}%>
<%if(!file1.equals("")){ //파일첨부%><img src="img/icon_file.gif"><%}%>
<%if(gongji.equals("3")){ //비밀글 %><img src="img/icon_secret.gif"><%} %>
</td>
<td align="center"><%=name %></td>
<td align="center"><%=signdate %></td>
</tr>
<tr><td colspan=4 height=1 width=100% bgcolor=#d1dee2></td></tr>
<%
}
rs.close();
stmt.close();
conn.close();
%>
<%if(total_record == 0){ //작성된 게시물이 없다면 %>
<tr><td colspan=4 align=center height=124>작성된 게시물이 없습니다.</td></tr>
<tr><td colspan=4 height=1 width=100% bgcolor=#d1dee2></td></tr>
<%} %>
</table>
<br>
<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<style>
.page_on {
padding:0px 5px;
color:red;
border:1px solid red;
font-weight:bold;
}
.page_off {
padding:0px 5px;
color:black;
border:1px solid black;
}
</style>
<%
// 페이징 처리 시작 /////////////////////////////
int total_block = 0;
int block = 0;
int first_page = 0;
int last_page = 0;
int direct_page = 0;
int my_page = 0;
total_block = (int)Math.ceil(total_page / (double)page_per_block); //총 블럭 수
block = (int)Math.ceil(page_now / (double)page_per_block); //현재 블럭
first_page = (block - 1) * page_per_block; //블럭내 시작하는 수
last_page = block * page_per_block; //블럭내 끝나는 수
if(total_block <= block) { //마지막 블럭일 때
last_page = total_page; //반복문 변수 처리
}
// 이전 블럭 처리
if(block != 1){ //첫 블럭이 아니라면
%>
<a href="list.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&page_now=<%=first_page%>"><img src="img/btn_left.gif"></a>
<%
}
// 블럭내 페이지 수 출력
for(direct_page = first_page + 1; direct_page <= last_page; direct_page++){
if(page_now == direct_page){
%>
<span class="page_on"><%=direct_page%></span>
<%
}else{
%>
<span class="page_off"><a href="list.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&page_now=<%=direct_page%>"><%=direct_page%></a></span>
<%
}
}
// 다음 블럭 처리
if(block < total_block) { //다음 블럭 존재
%>
<a href="list.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&page_now=<%=last_page + 1%>"><img src="img/btn_right.gif"></a>
<%
}
//페이징 처리 끝 /////////////////////////////
%>
</td>
<td align=right>
<%if(session_id != null){ //로그인 후 %>
<a href="write.jsp?code=<%=code%>">[글쓰기]</a>
<%}else{ %>
[로그인 후 작성하실 수 있습니다.]
<%} %>
</td>
</tr>
</table>
<br>
</center>
<%@ include file="/include/footer.jsp" %>
[실행화면]
댓글목록 0
등록된 댓글이 없습니다.