***À̺À¿ë´ÔÀÌ Á¦°øÇÑÀÚ·áÀÔ´Ï´Ù.***
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--- ÆÄÀϸí: guestbook.sql -----------------------------------
create table guestbook(
seq int auto_increment primary key,
name varchar(20),
email varchar(50),
home varchar(50),
passwd varchar(20),
content text not null,
now_date varchar(10),
ip varchar(20)
);
insert into guestbook values('','a','a','a','a','a','a','a');
create table guestreply(
replynum int auto_increment primary key,
seq int,
replyname varchar(20),
replycontent text,
replydate varchar(10),
replypasswd varchar(15)
);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--- ÆÄÀϸí: list.jsp -----------------------------------
<%@ include file="db.jsp" %>
<%@ include file="repcontent.jsp" %>
<%@ page import="java.sql.*,java.io.* ,java.text.* ,java.util.*" contentType="text/html;charset=euc-kr" %>
<%!
int no = 0;//±Û ¹øÈ£
int total_record = 0;//Àüü ±Û¼ö
int block = 0;//ÇöÀç ºí·Ï
int total_block = 0;//Àüü ºí·Ï
int total_page=0;//Àüü ÆäÀÌÁö
int page_size = 3;//ÇÑÆäÀÌÁö¿¡ º¸¿©ÁÙ ±Û¼ö
int block_size = 10;//ÇÑ ºí·ÏÀÇ ¹À½
int cnt_page=0;//ÇöÀç ÆäÀÌÁö
int first = 0;//óÀ½ ·¹Äڵ带 °¡Á®¿Ã À§Ä¡
int first_page = 0;//
int last_page = 0;//
int prev = 0;//ÀÌÀü ¸ñ·Ïº¸±â
int next = 0;//´ÙÀ½ ¸ñ·Ïº¸±â
int go_page = 0;//º¸¿©ÁÙ ½ÇÁúÀûÀÎ ÇöÀç ÆäÀÌÁö
%>
¹æ¸í·Ï
<%
Connection con = null;
Statement stmt = null;
ResultSet rs,rs1= null;
try{
request.setCharacterEncoding("euc-kr");
con = DriverManager.getConnection(dbhost, dbuser, dbpassword);
stmt = con.createStatement();
rs1 = stmt.executeQuery("select count(*) from guestbook");
if(rs1.next()){
total_record = rs1.getInt(1);
}
String str = request.getParameter("page");
if(str == null)
str = "1";
cnt_page = Integer.parseInt(str);
first = page_size * (cnt_page - 1);
no = total_record - first;
total_page = (int)Math.ceil((double)total_record / page_size );//0
total_block =(int)Math.ceil((double) total_page / block_size);//0
block = (int)Math.ceil((double)cnt_page / block_size);//0
first_page = (block - 1) * block_size;
last_page = block * block_size;
prev = first_page;
next = last_page + 1;
//go_page = first_page + 1;
if(total_block <= block)
last_page = total_page;
String sql = "select seq,name,email,home,passwd,content,now_date,ip from guestbook order by seq desc limit "+first+","+ page_size;
rs = stmt.executeQuery(sql);
%>
Total: <%=total_record%>°³ÀÇ ·¹ÄÚµå    (<%= cnt_page%>/<%=total_page %> ÆäÀÌÁö)
|
¹øÈ£ |
À̸§ |
ȨÆäÀÌÁö |
ip |
³¯Â¥ |
¼öÁ¤ |
»èÁ¦ |
<%
while(rs.next()) {
int seq=rs.getInt(1);
String name=rs.getString(2);
String email=rs.getString(3);
String home=rs.getString(4);
String passwd=rs.getString(5);
String content=rs.getString(6);
content = repcon(content,"\n","
");
String now_date=rs.getString(7);
String ip=rs.getString(8);
%>
<%
Statement stmt1 = con.createStatement();
rs1 = stmt1.executeQuery("select * from guestreply where seq ="+seq);
int cnt = 0;
while(rs1.next()){
cnt++;
int replynum = rs1.getInt(1);
String name2 = rs1.getString(3);
String replycontent = rs1.getString(4);
replycontent = repcon(replycontent,"\n","
");
%>
<%= no %>ÀÇ <%= cnt %>¹ø° ´ä±Û |
<%= name2 %> |
<%= replycontent %> |
»èÁ¦ |
<%
}
%>
<%
no--;
}//while
rs1.close();
rs.close();
stmt.close();
con.close();
}catch(SQLException se) {
out.println(se.getMessage());
}
%>
<%
//if(cntpage > 1){
//front = cntpage - 1;
%>
<%
if(block > 1){
%>
>prev
<%
}
for(go_page= first_page + 1;go_page<=last_page;go_page++){
if(go_page == cnt_page){
%>
[><%= go_page %>]
<%
}else{
%>
[><%= go_page %>]
<%
}
}
if(block < total_block){
%>
> next
<%
}
%>
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--- ÆÄÀϸí: db.jsp -----------------------------------
<%
String drivers = "org.gjt.mm.mysql.Driver";
String dbhost = "jdbc:mysql://localhost:3306/jsp_db";
//String dbhost = "jdbc:mysql://localhost:3306/jsp_db?useUnicode=true&characterEncoding=Euc-KR";
String dbuser = "captain7606";
String dbpassword = "lby0321";
try{
Class.forName(drivers).newInstance();
}catch(ClassNotFoundException e){
out.println(e);
}
%>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--- ÆÄÀϸí: write.html -----------------------------------
¹æ¸í·Ï