jsp留言板源代码二: 给jsp初学者.
程序员文章站
2024-02-26 11:40:34
作 者: precom (皮蛋) 2000.12.10guestbook.jsp ===========================
作 者: precom (皮蛋) 2000.12.10
guestbook.jsp
===========================
<html><head>
<meta content="text/html; charset=gb2312 " http-equiv=content-type>
<title>张家界电话黄页(网上114)</title></head>
<style type="text/css">
<!--
body { font-family: "宋体","arial narrow", "times new roman"; font-si
ze: 9pt }
.p1 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 12pt }
a:link { color: #00793d; text-decoration: none }
a:visited { text-decoration: none }
a:hover { text-decoration: underline}
td { font-family: "宋体", "arial narrow", "times new roman"; font-size
: 9pt }
.p2 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 9pt; line-height: 150% }
.p3 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 9pt; line-height: 120% }
-->
</style>
<body>
<%@ page contenttype="text/html; charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>
<jsp:usebean id="testinq" scope="page" class="ymbean.opdb" />
<%
int pages=1;
int pagesize=10;
int count=0;
int totalpages=0;
string countsql="",inqsql="",lwhere="",insertsql="",st="";
string lw_title="",lw_author="",pagetitle="",author_http="",author_e
mail="",lw_ico="",
lw_content="",lw_class1="";
string author_ip="",lw_time="",lw_class2="",lw_type="",zt_time="",zt
_author="";
int answer_num=0,click_num=0;
int inquire_item=1;
string inquire_itemt="",inquire_value="";
string lurlt="<a href=guestbook.jsp?",llink="";
lwhere=" where lw_type='z' "; //只显示主贴
/*
enumeration e = request.getparameternames();
while (e.hasmoreelements()) {
string name = (string) e.nextelement();
*/
try{
//取显示的页页序数
pages = new integer(request.getparameter("pages")).intvalue();
} catch (exception e) {}
try{
//取查询参数
inquire_item=new integer(request.getparameter("range")).intvalu
e();
inquire_value=new string(request.getparameter("findstr").getbyt
es("iso8859_1"));
if(inquire_item==0) inquire_itemt="lw_title";
else if(inquire_item==1) inquire_itemt="lw_content";
else if(inquire_item==2) inquire_itemt="lw_author";
else if(inquire_item==3) inquire_itemt="lw_time";
else if(inquire_item==4) inquire_itemt="lw_title";
lwhere=lwhere+" and "+inquire_itemt+" like '%"+inquire_value+"%
'";
lurlt=lurlt+"range="+inquire_item+"&findstr="+inquire_value+"&"
} catch (exception e) {}
try{
//取得参数 留言内容
lw_class1=new string(request.getparameter("gbname").getbytes("iso885
9_1"));
lw_title=new string(request.getparameter("lw_title").getbytes("iso88
59_1"));
lw_author=new string(request.getparameter("lw_author").getbytes("iso
8859_1"));
pagetitle=new string(request.getparameter("pagetitle").getbytes("iso
8859_1"));
author_http=new string(request.getparameter("author_http").getbytes(
"iso8859_1"));
author_email=new string(request.getparameter("author_email").getbyte
s("iso8859_1"));
lw_ico=request.getparameter("gifface");
lw_content=new string(request.getparameter("lw_content").getbytes("i
so8859_1"));
string requestmethod=request.getmethod();
requestmethod=requestmethod.touppercase();
if(requestmethod.indexof("post")<0)
{ out.print("非法操作!");
return;
}
//形成其他数据项
author_ip=request.getremoteaddr() ;
lw_time=testinq.getcurrentdate("yyyymmddhhmmss");
lw_class2="2";
lw_type=""+"z"; //主贴
zt_time=lw_time;
zt_author=lw_author;
answer_num=0;
click_num=0;
//================
st="','";
//保证留言所有数据项的长度在正常范围内
if(lw_title.length()>50) lw_title=lw_title.substring(0,50);
if(lw_author.length()>20) lw_author=lw_author.substring(0,20);
if(author_http.length()>40) author_http=author_http.substring(0,40);
if(author_email.length()>50) author_email=author_email.substring(0,4
0);
if(lw_content.length()>4000) lw_content=lw_content.substring(0,4000)
insertsql="insert into guestbook values('"+lw_title+st+lw_author+st+
author_http+st+
author_email+st+lw_ico+st+lw_time+"',"+answer_num+","+cli
ck_num+",'"+
author_ip+st+lw_class1+st+lw_class2+st+lw_type+st+zt_time
+st+zt_author+st+
lw_content+"')";
//out.print(insertsql);
//插入留言
try{
string lmsg=testinq.executeupdate(insertsql);
if(lmsg.indexof("executeupdate ok")<0)
out.print("lmsg="+lmsg);
}catch (exception e) { out.print("错误:"+e);}
} catch (exception e) {}
%>
<%
//验证留言输入项合法性的javascript
string ljs=" <script language=javascript> \n"+
" <!-- \n"+
" function validinput() \n"+
" {if(document.sign.lw_author.value==\"\") \n"+
" {alert(\"请填写您的大名。\"); \n"+
" document.sign.lw_author.focus(); \n"+
" return false;} \n"+
" if(document.sign.lw_title.value==\"\") \n"+
" {alert(\"请填写留言主题。\"); \n"+
" document.sign.lw_title.focus(); \n"+
" return false;} \n"+
" if (document.sign.author_email.value!=\"\") \n"+
" { if ((document.sign.author_email.value.indexof(\"@\")<0)//(document
.sign.author_email.value.indexof(\":\")!=-1)) \n"+
" {alert(\"您填写的email无效,请填写一个有效的email!\"); \n"+
" document.sign.author_emaill.focus(); \n"+
" return false; \n"+
" } \n"+
" } \n"+
" return true; \n"+
" } \n"+
" function validsearch() \n"+
" { if(document.frmsearch.findstr.value==\"\") \n"+
" {alert(\"不能搜索空串!\"); \n"+
" document.frmsearch.findstr.focus(); \n"+
" return false;} \n"+
" } \n"+
" //--> \n"+
" </script> ";
out.print(ljs);
%>
<%
//留言板界面首部
string ltop=" <div align=center> \n"+
" <center> \n"+
" <form action=guestbook.jsp method=post name=frmsearch> \n"+
" <input name=gbname type=hidden value=cnzjj_gt> \n"+
" <table align=center border=0 cellspacing=1 width=\"95%\"> \n"+
" <tbody> \n"+
" <tr> \n"+
" <td bgcolor=#336699 colspan=2 width=\"100%\"> \n"+
" <p align=center><font color=#ffffff face=楷体_gb2312 \n"+
" size=5>欢迎远方的朋友来张家界旅游观光</font></p></td></tr> \n"
+
" <tr bgcolor=#6699cc> \n"+
" <td align=left nowrap width=\"50%\">主页: <a \n"+
" href=\"http://www.zj.hn.cn\" target=_blank><font \n"+
" color=#ffffff>张家界旅游</font></a> 管理员: <a \n"
+
" href=\"mailto:dzx@mail.zj.hn.cninfo.net\"><font color=#ffffff>
一民</font></a> \n"+
" >><a \n"+
" href=\"http://www.zj.hn.cn \"><font \n"+
" color=#ffffff>管理</font></a> >><a \n"+
" href=\" http://www.zj.hn.cn \"><font \n"+
" color=#ffffff>申请</font></a> </td> \n"+
" <td align=right width=\"50%\"><select class=ourfont name=range s
ize=1> \n"+
" <option selected value=0>按主题</option> <option value=1>按内
容</option> \n"+
" <option value=2>按作者</option> <option value=3>按日期</opti
on> <option \n"+
" value=4>按主题&内容</option></select> <input name=findst
r> <input name=search onclick=\"return validsearch()\" type=submit val
ue=\"搜 索\"> \n"+
" </td></tr></tbody></table></form> \n"+
" <hr align=center noshade size=1 width=\"95%\"> \n"+
" </center></div> ";
out.print(ltop);
%>
<%
//显示最近时间发表的一页留言
countsql="select count(lw_title) from guestbook "+lwhere;
inqsql ="select lw_title,answer_num,click_num,lw_author,lw_time,expres
sion,"+
" author_email,lw_class1,lw_class2 from guestbook "+lwhere+" o
rder by lw_time desc" ;
if(pages>0)
{
try {
try{
resultset rcount=testinq.executequery(countsql);
if(rcount.next())
{
count = rcount.getint(1);
}
rcount.close();
} catch (exception el1) { out.println("count record error
: "+el1+"<br>" );
out.println(countsql);
}
totalpages=(int)(count/pagesize);
if(count>totalpages*pagesize) totalpages++;
st=""+
" <table align=center border=0 cellpadding=0 cellspacing=
0 width=\"95%\"> "+
" <tbody> <tr> <td align=middle bgcolor=#97badd width=\"1
00%\"><font color=#ff0000>"+
" 共 "+totalpages+" 页,"+count+"
条. "+" 当前页: "+pages+
" </font></td></tr></tbody></table><br> ";
out.print(st);
//out.print(" 共 "+totalpages+" 页,"+
count+" 条. "+" 当前页: "+pages+"<br>");
st=" <center> "+
" <table border=0 cellpadding=2 cellspacing=1 width=\"95%\"> "+
" <tbody> "+
" <tr> "+
" <td align=middle bgcolor=#6699cc width=\"55%\"><font "+
" color=#ffffff>留言主题</font></td> "+
" <td align=middle bgcolor=#6699cc width=50><font "+
" color=#ffffff>回应数</font></td> "+
" <td align=middle bgcolor=#6699cc width=40><font "+
" color=#ffffff>点击数</font></td> "+
" <td align=middle bgcolor=#6699cc width=100><font "+
" color=#ffffff>作者名</font></td> "+
" <td align=middle bgcolor=#6699cc width=140><font "+
" color=#ffffff>发表/回应时间</font></td></tr> ";
out.print(st);
if(count > 0 )
{
resultset rs = testinq.executequery(inqsql);
resultsetmetadata metadata = rs.getmetadata();
int i;
// 跳过pages -1 页,使cursor指向pages并准备显示
for(i=1;i<=(pages - 1)*pagesize;i++) rs.next();
//显示第pages页开始
string linestr="";
for(i=1;i<=pagesize;i++)
if(rs.next())
{
lw_title=rs.getstring("lw_title");
answer_num=rs.getint("answer_num");
click_num=rs.getint("click_num");
lw_author=rs.getstring("lw_author");
lw_time=rs.getstring("lw_time");
st=lw_time.substring(0,4)+"-"+lw_time.substring(4,6)+"-"
+lw_time.substring(6,8)+":"+
lw_time.substring(8,10)+":"+lw_time.substring(10,12)+
":"+lw_time.substring(12,14);
lw_ico=rs.getstring("expression");
author_email=rs.getstring("author_email");
lw_class1=rs.getstring("lw_class1");
lw_class2=rs.getstring("lw_class2");
llink="reply.jsp?lw_class1="+lw_class1+"&lw_class2="+lw_
class2+"&zt_time="+lw_time+
"&zt_author="+author_email;
linestr=" <tr bgcolor=#d5e8fd> \n" +
" <td bgcolor=#d5e8fd><img src=\""+lw_ico+".gif\
"><a "+
" href=\""+llink+" \">"+lw_title+"</a></td> "+
" <td align=middle>["+answer_num+"]</td>"+
" <td align=middle>"+click_num+"</td>"+
" <td align=middle><a href=\"mailto:"+author_ema
il+"\">"+lw_author+"</a></td>"+
" <td align=middle>"+st+"</td></tr>";
out.println(linestr);
}
rs.close();
//显示第pages页结束
st="</tbody></table><br>";
out.print(st);
int ifirst=1,ilast=totalpages,ipre,inext;
if(pages<=1) ipre=1;
else ipre=pages - 1;
if(pages>=totalpages) inext=totalpages;
else inext=pages + 1;
int n=(int)(count/pagesize);
if(n*pagesize<count) n++;
if(n>1)
{
//for(i=1;i<=n;i++) out.print("<a href=inquire.jsp?pages=
"+i+">"+i+" </a>");
//out.print("<hr align=center noshade size=1 width=\"95%\
">");
string lt1="返回主页",lt2="第一页",lt3="上一页",lt4="下一
页",lt5="最后一页",lt6="";
lt6="<a href=http://www.zj.hn.cn>"+ lt1 + " </
a>"+
lurlt + "pages="+ifirst+"><font color=red>"+lt2+"&nbs
p; </a>"+
lurlt + "pages="+ipre+"><font color=red>"+lt3+"
</a>" +
lurlt + "pages="+inext+"><font color=red>"+lt4+"
; </a>" +
lurlt + "pages="+ilast+"><font color=red>"+lt5+"
; </a>";
st=""+
" <table align=center border=0 cellpadding=0 cellspacing=
0 width=\"95%\"> "+
" <tbody> <tr> <td align=middle bgcolor=#97badd width=\"1
00%\"><font color=#ff0000>"+
lt6+
" </font></td></tr></tbody></table><br> ";
out.print(st);
}
}
} catch (exception e) { out.println("error: "+e); }
}
%>
<%
//留言板界面尾部
string lbottom="";
lbottom=lbottom+
" \n"+
" <form action=guestbook.jsp method=post name=sign> \n"+
" <input name=gbname type=hidden value=cnzjj_gt> \n"+
" <input name=pages type=hidden value=1> \n"+
" <table bgcolor=#d5e8fd border=0 cellspacing=1 width=\"95%\"> \n"+
" <tbody> \n"+
" <tr> \n"+
" <td align=middle bgcolor=#e6e6fa colspan=2 nowrap><strong><font
color=blue \n"+
" face=楷体_gb2312 size=5>发 表 意 见</font></strong> &nbs
p; [加*的内容必须填写] </td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"45%\"> \n"+
" <div align=left> \n"+
" <table bgcolor=#d5e8fd border=0 cellspacing=1 width=\"100%\">
\n"+
" <tbody> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*留言主题:<input maxlength=40 n
ame=lw_title \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*网上大名:<input maxlength=18 n
ame=lw_author \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\"> 主页标题:<input maxlength
=40 name=pagetitle \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\"> 主页地址:<input maxlength
=255 name=author_http \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*电子邮件:<input maxlength=40 n
ame=author_email \n"+
" size=36></td></tr></tbody></table></div></td> \n"+
" <td nowrap valign=top width=\"55%\"> \n"+
" <div align=left> \n"+
" <table bgcolor=#b6d7fc border=0 cellspacing=1 width=\"100%\">
\n"+
" <tbody> \n"+
" <tr> \n"+
" <td width=\"100%\">请在下面填写你的留言:</td></tr> \n"+
" <tr> \n"+
" <td width=\"100%\"><textarea cols=50 name=lw_content rows=
7></textarea></td></tr></tbody></table></div></td></tr> \n"+
" <tr> \n"+
" <td bgcolor=#fbf7ea colspan=2 nowrap>表情\n"+
" <input name=gifface type=radio value=1 checked><img \n"+
" alt=\"1.gif (152 bytes)\" height=15 src=\"1.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=2><img alt=\"2.gif (174 bytes)\"
height=15 \n"+
" src=\"2.gif\" width=15> <input name=gifface type=radio value=3
><img \n"+
" alt=\"3.gif (147 bytes)\" height=15 src=\"3.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=4><img alt=\"4.gif (172 bytes)\"
height=15 \n"+
" src=\"4.gif\" width=15> <input name=gifface type=radio value=5
><img \n"+
" alt=\"5.gif (118 bytes)\" height=15 src=\"5.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=6><img alt=\"6.gif (180 bytes)\"
height=15 \n"+
" src=\"6.gif\" width=15> <input name=gifface type=radio value=7
><img \n"+
" alt=\"7.gif (180 bytes)\" height=15 src=\"7.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=8><img alt=\"8.gif (96 bytes)\"
height=15 \n"+
" src=\"8.gif\" width=15> <input name=gifface type=radio value=9
><img \n"+
" alt=\"9.gif (162 bytes)\" height=15 src=\"9.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=10><img alt=\"10.gif (113 bytes)
\" height=15 \n"+
" src=\"10.gif\" width=15> <input name=gifface type=radio value=
11><img \n"+
" alt=\"11.gif (93 bytes)\" height=15 src=\"11.gif\" width=15> <
input \n"+
" name=gifface type=radio value=12> <img alt=\"12.gif (149 bytes
)\" height=14 \n"+
" src=\"12.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=13> <img alt=\"13.gif (149 bytes
)\" height=14 \n"+
" src=\"13.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=14> <img alt=\"14.gif (149 bytes
)\" height=14 \n"+
" src=\"14.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=15> <img alt=\"15.gif (149 bytes
)\" height=14 \n"+
" src=\"15.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=16> <img alt=\"16.gif (149 bytes
)\" height=14 \n"+
" src=\"16.gif\" width=15> </td> \n"+
" </tr> \n"+
" <tr> \n"+
" <td align=middle colspan=2 nowrap><input name=cmdgo onclick=\"re
turn validinput()\" type=submit value=\"提 交\"> \n"+
" <input name=cmdprev onclick=\"return validinput()\" type=submit valu
e=\"预 览\"> \n"+
" <input name=cmdcancel type=reset value=\"重 写\"> <inpu
t name=cmdback onclick=javascript:history.go(-1) type=button value=\"返
回\"> \n"+
" </td></tr></tbody></table></form></center></div> ";
out.print(lbottom);
%>
</body></html>
guestbook.jsp
===========================
<html><head>
<meta content="text/html; charset=gb2312 " http-equiv=content-type>
<title>张家界电话黄页(网上114)</title></head>
<style type="text/css">
<!--
body { font-family: "宋体","arial narrow", "times new roman"; font-si
ze: 9pt }
.p1 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 12pt }
a:link { color: #00793d; text-decoration: none }
a:visited { text-decoration: none }
a:hover { text-decoration: underline}
td { font-family: "宋体", "arial narrow", "times new roman"; font-size
: 9pt }
.p2 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 9pt; line-height: 150% }
.p3 { font-family: "宋体", "arial narrow", "times new roman"; font-siz
e: 9pt; line-height: 120% }
-->
</style>
<body>
<%@ page contenttype="text/html; charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>
<jsp:usebean id="testinq" scope="page" class="ymbean.opdb" />
<%
int pages=1;
int pagesize=10;
int count=0;
int totalpages=0;
string countsql="",inqsql="",lwhere="",insertsql="",st="";
string lw_title="",lw_author="",pagetitle="",author_http="",author_e
mail="",lw_ico="",
lw_content="",lw_class1="";
string author_ip="",lw_time="",lw_class2="",lw_type="",zt_time="",zt
_author="";
int answer_num=0,click_num=0;
int inquire_item=1;
string inquire_itemt="",inquire_value="";
string lurlt="<a href=guestbook.jsp?",llink="";
lwhere=" where lw_type='z' "; //只显示主贴
/*
enumeration e = request.getparameternames();
while (e.hasmoreelements()) {
string name = (string) e.nextelement();
*/
try{
//取显示的页页序数
pages = new integer(request.getparameter("pages")).intvalue();
} catch (exception e) {}
try{
//取查询参数
inquire_item=new integer(request.getparameter("range")).intvalu
e();
inquire_value=new string(request.getparameter("findstr").getbyt
es("iso8859_1"));
if(inquire_item==0) inquire_itemt="lw_title";
else if(inquire_item==1) inquire_itemt="lw_content";
else if(inquire_item==2) inquire_itemt="lw_author";
else if(inquire_item==3) inquire_itemt="lw_time";
else if(inquire_item==4) inquire_itemt="lw_title";
lwhere=lwhere+" and "+inquire_itemt+" like '%"+inquire_value+"%
'";
lurlt=lurlt+"range="+inquire_item+"&findstr="+inquire_value+"&"
} catch (exception e) {}
try{
//取得参数 留言内容
lw_class1=new string(request.getparameter("gbname").getbytes("iso885
9_1"));
lw_title=new string(request.getparameter("lw_title").getbytes("iso88
59_1"));
lw_author=new string(request.getparameter("lw_author").getbytes("iso
8859_1"));
pagetitle=new string(request.getparameter("pagetitle").getbytes("iso
8859_1"));
author_http=new string(request.getparameter("author_http").getbytes(
"iso8859_1"));
author_email=new string(request.getparameter("author_email").getbyte
s("iso8859_1"));
lw_ico=request.getparameter("gifface");
lw_content=new string(request.getparameter("lw_content").getbytes("i
so8859_1"));
string requestmethod=request.getmethod();
requestmethod=requestmethod.touppercase();
if(requestmethod.indexof("post")<0)
{ out.print("非法操作!");
return;
}
//形成其他数据项
author_ip=request.getremoteaddr() ;
lw_time=testinq.getcurrentdate("yyyymmddhhmmss");
lw_class2="2";
lw_type=""+"z"; //主贴
zt_time=lw_time;
zt_author=lw_author;
answer_num=0;
click_num=0;
//================
st="','";
//保证留言所有数据项的长度在正常范围内
if(lw_title.length()>50) lw_title=lw_title.substring(0,50);
if(lw_author.length()>20) lw_author=lw_author.substring(0,20);
if(author_http.length()>40) author_http=author_http.substring(0,40);
if(author_email.length()>50) author_email=author_email.substring(0,4
0);
if(lw_content.length()>4000) lw_content=lw_content.substring(0,4000)
insertsql="insert into guestbook values('"+lw_title+st+lw_author+st+
author_http+st+
author_email+st+lw_ico+st+lw_time+"',"+answer_num+","+cli
ck_num+",'"+
author_ip+st+lw_class1+st+lw_class2+st+lw_type+st+zt_time
+st+zt_author+st+
lw_content+"')";
//out.print(insertsql);
//插入留言
try{
string lmsg=testinq.executeupdate(insertsql);
if(lmsg.indexof("executeupdate ok")<0)
out.print("lmsg="+lmsg);
}catch (exception e) { out.print("错误:"+e);}
} catch (exception e) {}
%>
<%
//验证留言输入项合法性的javascript
string ljs=" <script language=javascript> \n"+
" <!-- \n"+
" function validinput() \n"+
" {if(document.sign.lw_author.value==\"\") \n"+
" {alert(\"请填写您的大名。\"); \n"+
" document.sign.lw_author.focus(); \n"+
" return false;} \n"+
" if(document.sign.lw_title.value==\"\") \n"+
" {alert(\"请填写留言主题。\"); \n"+
" document.sign.lw_title.focus(); \n"+
" return false;} \n"+
" if (document.sign.author_email.value!=\"\") \n"+
" { if ((document.sign.author_email.value.indexof(\"@\")<0)//(document
.sign.author_email.value.indexof(\":\")!=-1)) \n"+
" {alert(\"您填写的email无效,请填写一个有效的email!\"); \n"+
" document.sign.author_emaill.focus(); \n"+
" return false; \n"+
" } \n"+
" } \n"+
" return true; \n"+
" } \n"+
" function validsearch() \n"+
" { if(document.frmsearch.findstr.value==\"\") \n"+
" {alert(\"不能搜索空串!\"); \n"+
" document.frmsearch.findstr.focus(); \n"+
" return false;} \n"+
" } \n"+
" //--> \n"+
" </script> ";
out.print(ljs);
%>
<%
//留言板界面首部
string ltop=" <div align=center> \n"+
" <center> \n"+
" <form action=guestbook.jsp method=post name=frmsearch> \n"+
" <input name=gbname type=hidden value=cnzjj_gt> \n"+
" <table align=center border=0 cellspacing=1 width=\"95%\"> \n"+
" <tbody> \n"+
" <tr> \n"+
" <td bgcolor=#336699 colspan=2 width=\"100%\"> \n"+
" <p align=center><font color=#ffffff face=楷体_gb2312 \n"+
" size=5>欢迎远方的朋友来张家界旅游观光</font></p></td></tr> \n"
+
" <tr bgcolor=#6699cc> \n"+
" <td align=left nowrap width=\"50%\">主页: <a \n"+
" href=\"http://www.zj.hn.cn\" target=_blank><font \n"+
" color=#ffffff>张家界旅游</font></a> 管理员: <a \n"
+
" href=\"mailto:dzx@mail.zj.hn.cninfo.net\"><font color=#ffffff>
一民</font></a> \n"+
" >><a \n"+
" href=\"http://www.zj.hn.cn \"><font \n"+
" color=#ffffff>管理</font></a> >><a \n"+
" href=\" http://www.zj.hn.cn \"><font \n"+
" color=#ffffff>申请</font></a> </td> \n"+
" <td align=right width=\"50%\"><select class=ourfont name=range s
ize=1> \n"+
" <option selected value=0>按主题</option> <option value=1>按内
容</option> \n"+
" <option value=2>按作者</option> <option value=3>按日期</opti
on> <option \n"+
" value=4>按主题&内容</option></select> <input name=findst
r> <input name=search onclick=\"return validsearch()\" type=submit val
ue=\"搜 索\"> \n"+
" </td></tr></tbody></table></form> \n"+
" <hr align=center noshade size=1 width=\"95%\"> \n"+
" </center></div> ";
out.print(ltop);
%>
<%
//显示最近时间发表的一页留言
countsql="select count(lw_title) from guestbook "+lwhere;
inqsql ="select lw_title,answer_num,click_num,lw_author,lw_time,expres
sion,"+
" author_email,lw_class1,lw_class2 from guestbook "+lwhere+" o
rder by lw_time desc" ;
if(pages>0)
{
try {
try{
resultset rcount=testinq.executequery(countsql);
if(rcount.next())
{
count = rcount.getint(1);
}
rcount.close();
} catch (exception el1) { out.println("count record error
: "+el1+"<br>" );
out.println(countsql);
}
totalpages=(int)(count/pagesize);
if(count>totalpages*pagesize) totalpages++;
st=""+
" <table align=center border=0 cellpadding=0 cellspacing=
0 width=\"95%\"> "+
" <tbody> <tr> <td align=middle bgcolor=#97badd width=\"1
00%\"><font color=#ff0000>"+
" 共 "+totalpages+" 页,"+count+"
条. "+" 当前页: "+pages+
" </font></td></tr></tbody></table><br> ";
out.print(st);
//out.print(" 共 "+totalpages+" 页,"+
count+" 条. "+" 当前页: "+pages+"<br>");
st=" <center> "+
" <table border=0 cellpadding=2 cellspacing=1 width=\"95%\"> "+
" <tbody> "+
" <tr> "+
" <td align=middle bgcolor=#6699cc width=\"55%\"><font "+
" color=#ffffff>留言主题</font></td> "+
" <td align=middle bgcolor=#6699cc width=50><font "+
" color=#ffffff>回应数</font></td> "+
" <td align=middle bgcolor=#6699cc width=40><font "+
" color=#ffffff>点击数</font></td> "+
" <td align=middle bgcolor=#6699cc width=100><font "+
" color=#ffffff>作者名</font></td> "+
" <td align=middle bgcolor=#6699cc width=140><font "+
" color=#ffffff>发表/回应时间</font></td></tr> ";
out.print(st);
if(count > 0 )
{
resultset rs = testinq.executequery(inqsql);
resultsetmetadata metadata = rs.getmetadata();
int i;
// 跳过pages -1 页,使cursor指向pages并准备显示
for(i=1;i<=(pages - 1)*pagesize;i++) rs.next();
//显示第pages页开始
string linestr="";
for(i=1;i<=pagesize;i++)
if(rs.next())
{
lw_title=rs.getstring("lw_title");
answer_num=rs.getint("answer_num");
click_num=rs.getint("click_num");
lw_author=rs.getstring("lw_author");
lw_time=rs.getstring("lw_time");
st=lw_time.substring(0,4)+"-"+lw_time.substring(4,6)+"-"
+lw_time.substring(6,8)+":"+
lw_time.substring(8,10)+":"+lw_time.substring(10,12)+
":"+lw_time.substring(12,14);
lw_ico=rs.getstring("expression");
author_email=rs.getstring("author_email");
lw_class1=rs.getstring("lw_class1");
lw_class2=rs.getstring("lw_class2");
llink="reply.jsp?lw_class1="+lw_class1+"&lw_class2="+lw_
class2+"&zt_time="+lw_time+
"&zt_author="+author_email;
linestr=" <tr bgcolor=#d5e8fd> \n" +
" <td bgcolor=#d5e8fd><img src=\""+lw_ico+".gif\
"><a "+
" href=\""+llink+" \">"+lw_title+"</a></td> "+
" <td align=middle>["+answer_num+"]</td>"+
" <td align=middle>"+click_num+"</td>"+
" <td align=middle><a href=\"mailto:"+author_ema
il+"\">"+lw_author+"</a></td>"+
" <td align=middle>"+st+"</td></tr>";
out.println(linestr);
}
rs.close();
//显示第pages页结束
st="</tbody></table><br>";
out.print(st);
int ifirst=1,ilast=totalpages,ipre,inext;
if(pages<=1) ipre=1;
else ipre=pages - 1;
if(pages>=totalpages) inext=totalpages;
else inext=pages + 1;
int n=(int)(count/pagesize);
if(n*pagesize<count) n++;
if(n>1)
{
//for(i=1;i<=n;i++) out.print("<a href=inquire.jsp?pages=
"+i+">"+i+" </a>");
//out.print("<hr align=center noshade size=1 width=\"95%\
">");
string lt1="返回主页",lt2="第一页",lt3="上一页",lt4="下一
页",lt5="最后一页",lt6="";
lt6="<a href=http://www.zj.hn.cn>"+ lt1 + " </
a>"+
lurlt + "pages="+ifirst+"><font color=red>"+lt2+"&nbs
p; </a>"+
lurlt + "pages="+ipre+"><font color=red>"+lt3+"
</a>" +
lurlt + "pages="+inext+"><font color=red>"+lt4+"
; </a>" +
lurlt + "pages="+ilast+"><font color=red>"+lt5+"
; </a>";
st=""+
" <table align=center border=0 cellpadding=0 cellspacing=
0 width=\"95%\"> "+
" <tbody> <tr> <td align=middle bgcolor=#97badd width=\"1
00%\"><font color=#ff0000>"+
lt6+
" </font></td></tr></tbody></table><br> ";
out.print(st);
}
}
} catch (exception e) { out.println("error: "+e); }
}
%>
<%
//留言板界面尾部
string lbottom="";
lbottom=lbottom+
" \n"+
" <form action=guestbook.jsp method=post name=sign> \n"+
" <input name=gbname type=hidden value=cnzjj_gt> \n"+
" <input name=pages type=hidden value=1> \n"+
" <table bgcolor=#d5e8fd border=0 cellspacing=1 width=\"95%\"> \n"+
" <tbody> \n"+
" <tr> \n"+
" <td align=middle bgcolor=#e6e6fa colspan=2 nowrap><strong><font
color=blue \n"+
" face=楷体_gb2312 size=5>发 表 意 见</font></strong> &nbs
p; [加*的内容必须填写] </td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"45%\"> \n"+
" <div align=left> \n"+
" <table bgcolor=#d5e8fd border=0 cellspacing=1 width=\"100%\">
\n"+
" <tbody> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*留言主题:<input maxlength=40 n
ame=lw_title \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*网上大名:<input maxlength=18 n
ame=lw_author \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\"> 主页标题:<input maxlength
=40 name=pagetitle \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\"> 主页地址:<input maxlength
=255 name=author_http \n"+
" size=36></td></tr> \n"+
" <tr> \n"+
" <td nowrap width=\"100%\">*电子邮件:<input maxlength=40 n
ame=author_email \n"+
" size=36></td></tr></tbody></table></div></td> \n"+
" <td nowrap valign=top width=\"55%\"> \n"+
" <div align=left> \n"+
" <table bgcolor=#b6d7fc border=0 cellspacing=1 width=\"100%\">
\n"+
" <tbody> \n"+
" <tr> \n"+
" <td width=\"100%\">请在下面填写你的留言:</td></tr> \n"+
" <tr> \n"+
" <td width=\"100%\"><textarea cols=50 name=lw_content rows=
7></textarea></td></tr></tbody></table></div></td></tr> \n"+
" <tr> \n"+
" <td bgcolor=#fbf7ea colspan=2 nowrap>表情\n"+
" <input name=gifface type=radio value=1 checked><img \n"+
" alt=\"1.gif (152 bytes)\" height=15 src=\"1.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=2><img alt=\"2.gif (174 bytes)\"
height=15 \n"+
" src=\"2.gif\" width=15> <input name=gifface type=radio value=3
><img \n"+
" alt=\"3.gif (147 bytes)\" height=15 src=\"3.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=4><img alt=\"4.gif (172 bytes)\"
height=15 \n"+
" src=\"4.gif\" width=15> <input name=gifface type=radio value=5
><img \n"+
" alt=\"5.gif (118 bytes)\" height=15 src=\"5.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=6><img alt=\"6.gif (180 bytes)\"
height=15 \n"+
" src=\"6.gif\" width=15> <input name=gifface type=radio value=7
><img \n"+
" alt=\"7.gif (180 bytes)\" height=15 src=\"7.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=8><img alt=\"8.gif (96 bytes)\"
height=15 \n"+
" src=\"8.gif\" width=15> <input name=gifface type=radio value=9
><img \n"+
" alt=\"9.gif (162 bytes)\" height=15 src=\"9.gif\" width=15> <i
nput \n"+
" name=gifface type=radio value=10><img alt=\"10.gif (113 bytes)
\" height=15 \n"+
" src=\"10.gif\" width=15> <input name=gifface type=radio value=
11><img \n"+
" alt=\"11.gif (93 bytes)\" height=15 src=\"11.gif\" width=15> <
input \n"+
" name=gifface type=radio value=12> <img alt=\"12.gif (149 bytes
)\" height=14 \n"+
" src=\"12.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=13> <img alt=\"13.gif (149 bytes
)\" height=14 \n"+
" src=\"13.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=14> <img alt=\"14.gif (149 bytes
)\" height=14 \n"+
" src=\"14.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=15> <img alt=\"15.gif (149 bytes
)\" height=14 \n"+
" src=\"15.gif\" width=15> \n"+
" <input \n"+
" name=gifface type=radio value=16> <img alt=\"16.gif (149 bytes
)\" height=14 \n"+
" src=\"16.gif\" width=15> </td> \n"+
" </tr> \n"+
" <tr> \n"+
" <td align=middle colspan=2 nowrap><input name=cmdgo onclick=\"re
turn validinput()\" type=submit value=\"提 交\"> \n"+
" <input name=cmdprev onclick=\"return validinput()\" type=submit valu
e=\"预 览\"> \n"+
" <input name=cmdcancel type=reset value=\"重 写\"> <inpu
t name=cmdback onclick=javascript:history.go(-1) type=button value=\"返
回\"> \n"+
" </td></tr></tbody></table></form></center></div> ";
out.print(lbottom);
%>
</body></html>
上一篇: Java微信公众平台开发(12) 微信用户信息的获取
下一篇: 使用java执行定时任务示例