bbs/list.jsp > JSP

본문 바로가기
사이트 내 전체검색

JSP

bbs/list.jsp

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 404회 작성일 23-03-15 13:41

본문

<%@ 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();

%>


<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%>"><%=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"; // 최신순 정렬

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%>"><%=subject %></a>

<%}else{ %>

<%=subject %>

<%} %>

<%}else{ //일반글 %>

<a href="view.jsp?code=<%=code%>&uid=<%=uid%>"><%=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></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" %>






[실행화면]

80d129cf9bec268d3bf296c8a85bb8a4_1678855694_5598.png



80d129cf9bec268d3bf296c8a85bb8a4_1678855795_3671.png 


추천0

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
8
어제
140
최대
10,760
전체
269,404
Copyright © dancePKT . All rights reserved.