bbs5/list.jsp
페이지 정보
본문
<%@ 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게시판";
}else if(code.equals("cal")){
bbs_title = "달력게시판";
}
%>
<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>
<%
Calendar cal = Calendar.getInstance();
//현재 년, 월, 일
int nYear, nMonth, nDate;
if(request.getParameter("nYear") != null){
nYear = Integer.parseInt(request.getParameter("nYear"));
}else{
nYear = cal.get(cal.YEAR);
}
if(request.getParameter("nMonth") != null){
nMonth = Integer.parseInt(request.getParameter("nMonth"));
}else{
nMonth = cal.get(cal.MONTH) + 1;
}
if(request.getParameter("nDate") != null){
nDate = Integer.parseInt(request.getParameter("nDate"));
}else{
nDate = cal.get(cal.DATE) ;
}
//전월,다음월
int preYear = nYear;
int preMonth = nMonth - 1;
int nextYear = nYear;
int nextMonth = nMonth + 1;
if(nMonth == 12){
nextYear = nYear + 1;
nextMonth = 1;
}
if(nMonth == 1){
preYear = nYear - 1;
preMonth = 12;
}
%>
<a href="list.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&nYear=<%=preYear%>&nMonth=<%=preMonth%>"><img src="img/btn_left.gif"></a>
<%=nYear%>년 <%=nMonth%>월
<a href="list.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&nYear=<%=nextYear%>&nMonth=<%=nextMonth%>"><img src="img/btn_right.gif"></a>
</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">
<%
// 공지글
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 name = rs_top.getString("name");
String signdate = rs_top.getString("signdate");
String file1 = rs_top.getString("file1");
%>
<tr><td colspan=7 height=1 width=100% bgcolor=#d1dee2></td></tr>
<tr height="26" bgcolor="#fff6fa">
<td width="60" align="center"><font color=red>[공지]</font></td>
<td width="440">
<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>
<%
}
rs_top.close();
stmt_top.close();
conn_top.close();
%>
</table>
<!-- 달력 -->
<table width="700" border="1" cellpadding="0" cellspacing="0">
<tr height=30>
<th width=100 style="color:red">일</th> <!-- 일=1 -->
<th width=100>월</th> <!-- 월=2 -->
<th width=100>화</th> <!-- 화=3 -->
<th width=100>수</th> <!-- 수=4 -->
<th width=100>목</th> <!-- 목=5 -->
<th width=100>금</th> <!-- 금=6 -->
<th width=100 style="color:blue">토</th> <!-- 토=7 -->
</tr>
<tr height=50>
<%
cal.set(nYear, nMonth, 1); //현재 날짜를 현재 월의 1일로 설정
int startDay=cal.get(Calendar.DAY_OF_WEEK); //현재날짜(1일)의 요일
int end=cal.getActualMaximum(Calendar.DAY_OF_MONTH); //이 달의 끝나는 날
int br=0; //7일마다 줄 바꾸기
for(int i=0; i<(startDay-1); i++) { //빈칸출력
out.print("<td></td>");
br++;
}
Connection conn_cal=DriverManager.getConnection(url, user, password);
Statement stmt_cal=conn_cal.createStatement();
for(int i=1; i<=end; i++) { //날짜출력
%>
<td valign=top style="padding-left:4px;">
<%if(session_id != null){ //로그인 후 %>
<a href="write.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&nYear=<%=nYear%>&nMonth=<%=nMonth%>&nDate=<%=i%>"><%=i%></a>
<%}else{ %>
<a onclick="alert('로그인 후 작성하실 수 있습니다.')" style="cursor:pointer"><%=i%></a>
<%} %>
<br>
<%
// 일반,비밀글 목록
String sql_cal =" select * from "+code+" where gongji != '1' and nyear="+nYear+" and nmonth="+nMonth+" and ndate="+i+" "+sql_search+" order by uid desc";
ResultSet rs_cal=stmt_cal.executeQuery(sql_cal);
while(rs_cal.next()){
int uid = rs_cal.getInt("uid");
%>
<a href="view.jsp?code=<%=code%>&field=<%=field%>&search=<%=search%>&nYear=<%=nYear%>&nMonth=<%=nMonth%>&nDate=<%=i%>&uid=<%=uid%>">
<%=rs_cal.getString("subject") %>
</a><br>
<%
}
rs_cal.close();
out.print("</td>");
br++;
if((br%7)==0 && i!=end) {
out.println("</tr><tr height=50>");
}
}
stmt_cal.close();
conn_cal.close();
while((br++)%7!=0){ //말일 이후 빈칸출력
out.print("<td></td>");
}
%>
</table>
<br>
</center>
<%@ include file="/include/footer.jsp" %>
- 이전글▣ include/dbconnection.jsp ( 수정 ) 24.10.29
- 다음글bbs5/write.jsp 24.10.29
댓글목록
등록된 댓글이 없습니다.