jsp留言板源代码二

作%20者:%20precom%20(皮蛋)%202000.12.10%20%20

guestbook.jsp%20%20

张家界电话黄页(网上114)

int%20pages=1;
int%20pagesize=10;
int%20count=0;
int%20totalpages=0;%20%20

String%20countsql=””,inqsql=””,lwhere=””,insertsql=””,st=””;%20%20

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%20answer_num=0,click_num=0;
int%20inquire_item=1;
String%20inquire_itemt=””,inquire_value=””;
String%20lurlt=”[
lwhere=”%20where%20lw_type=’z’%20″;%20//只显示主贴%20%20

/*
Enumeration%20e%20=%20request.getParameterNames();
while%20(e.hasMoreElements())%20{
String%20name%20=%20(String)%20e.nextElement();
*/
try{
//取显示的页页序数
pages%20=%20new%20Integer(request.getParameter(“pages”)).intValue();
}%20catch%20(Exception%20e)%20{}
try{
//取查询参数
inquire_item=new%20Integer(request.getParameter(“range”)).intValu
e();
inquire_value=new%20String(request.getParameter(“findstr”).getByt
es(“ISO8859_1”));
if(inquire_item==0)%20inquire_itemt=”lw_title”;
else%20if(inquire_item==1)%20inquire_itemt=”lw_content”;
else%20if(inquire_item==2)%20inquire_itemt=”lw_author”;
else%20if(inquire_item==3)%20inquire_itemt=”lw_time”;
else%20if(inquire_item==4)%20inquire_itemt=”lw_title”;
lwhere=lwhere+”%20and%20″+inquire_itemt+”%20like%20’%”+inquire_value+”%
‘”;
lurlt=lurlt+”range=”+inquire_item+”&findstr=”+inquire_value+”&”%20%20

}%20catch%20(Exception%20e)%20{}%20%20

try{
//取得参数%20留言内容
lw_class1=new%20String(request.getParameter(“gbname”).getBytes(“ISO885
9_1″));
lw_title=new%20String(request.getParameter(“lw_title”).getBytes(“ISO88
59_1″));
lw_author=new%20String(request.getParameter(“lw_author”).getBytes(“ISO
8859_1″));
pagetitle=new%20String(request.getParameter(“pagetitle”).getBytes(“ISO
8859_1″));
author_http=new%20String(request.getParameter(“author_http”).getBytes(
“ISO8859_1”));
author_email=new%20String(request.getParameter(“author_email”).getByte
s(“ISO8859_1”));
lw_ico=request.getParameter(“gifface”);
lw_content=new%20String(request.getParameter(“lw_content”).getBytes(“I
SO8859_1″));
String%20requestMethod=request.getMethod();
requestMethod=requestMethod.toUpperCase();
if(requestMethod.indexOf(“POST”)<0)
{%20out.print(“非法操作!”);
return;
}%20%20

//形成其他数据项
author_ip=request.getRemoteAddr()%20;
lw_time=testInq.getCurrentDate(“yyyyMMddHHmmss”);
lw_class2=”2″;
lw_type=””+”z”;%20//主贴
zt_time=lw_time;
zt_author=lw_author;
answer_num=0;
click_num=0;
//================
st=”‘,'”;
//保证留言所有数据项的长度在正常范围内
if(lw_title.length()>50)%20lw_title=lw_title.substring(0,50);
if(lw_author.length()>20)%20lw_author=lw_author.substring(0,20);
if(author_http.length()>40)
author_http=author_http.substring(0,40);%20%20

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)%20%20

insertsql=”insert%20into%20guestbook%20values(‘”+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%20lmsg=testInq.executeUpdate(insertsql);
if(lmsg.indexOf(“executeUpdate%20ok”)<0)
out.print(“lmsg=”+lmsg);%20%20

}catch%20(Exception%20e)%20{%20out.print(“错误:”+e);}
}%20catch%20(Exception%20e)%20{}
%>%20%20

//验证留言输入项合法性的javascript
String
ljs=”](;)

“;
out.print(ljs);
%>%20%20

//留言板界面首部
String%20ltop=”

n”+

n”+

n”+
“%20n”+

n”+

n”+

n”+

n”+

“%20size=5>欢迎远方的朋友来张家界旅游观光

n”%20%20

n”+

主页:%20″%20href=””%20target=_blank>”
color=#ffffff>张家界旅游%20管理员:%20+
“%20href=”mailto:dzx@mail.zj.hn.cninfo.net”>
一民%20n”+
“%20>>”%20href=”%20″>”%20color=#ffffff>管理
>>”%20href=”%20%20”>”%20color=#ffffff>申请

n”+

ize=1>%20n”+
“%20按主题%20按内
容%20n”+
“%20按作者%20按日期ON>%20″%20value=4>按主题&内容%20r>%20ue=”搜%20索”>
n”+

n”+


n”+

<>%20″;
out.print(ltop);
%>%20%20

//显示最近时间发表的一页留言
countsql=”select%20count(lw_title)%20from%20guestbook%20″+lwhere;
inqsql%20=”select
lw_title,answer_num,click_num,lw_author,lw_time,expres
sion,”+
“%20author_email,lw_class1,lw_class2%20from%20guestbook%20″+lwhere+”%20o
rder%20by%20lw_time%20desc”%20;%20%20

if(pages>0)
{
try%20{
try{
ResultSet%20rcount=testInq.executeQuery(countsql);
if(rcount.next())
{
count%20=%20rcount.getInt(1);
}
rcount.close();
}%20catch%20(Exception%20el1)%20{%20out.println(“count%20record%20error
:%20″+el1+”
“%20);
out.println(countsql);
}%20%20

totalpages=(int)(count/pagesize);
if(count>totalpages*pagesize)%20totalpages++;
st=””+

0%20width=”95%”>%20″+

00%”>”+
“%20共%20″+totalpages+”%20页,”+count+”
条.%20″+”%20当前页:%20″+pages+

“;%20%20

out.print(st);%20%20

//out.print(“%20共%20″+totalpages+”%20页,”+
count+”%20条.%20″+”%20当前页:%20″+pages+”
“);%20%20

st=”

“+

“+

“+

“+

“%20color=#ffffff>留言主题

“+

“%20color=#ffffff>回应数

“+

“%20color=#ffffff>点击数

“+

“%20color=#ffffff>作者名

“+

“%20color=#ffffff>发表/回应时间

“;
out.print(st);%20%20

if(count%20>%200%20)
{
ResultSet%20rs%20=%20testInq.executeQuery(inqsql);
ResultSetMetaData%20metaData%20=%20rs.getMetaData();%20%20

int%20i;
//%20跳过pages%20-1%20页,使cursor指向pages并准备显示
for(i=1;i<=(pages%20-%201)*pagesize;i++)%20rs.next();
//显示第pages页开始
String%20linestr=””;
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=”

n”%20+

“>”
href=””+llink+”%20″>”+lw_title+”

“+

[“+answer_num+”]

“+

“+click_num+”

“+

il+””>”+lw_author+”

“+

“+st+”

“;%20%20

out.println(linestr);%20%20

}
rs.close();
//显示第pages页结束
st=”

“;
out.print(st);%20%20

int%20iFirst=1,iLast=totalpages,iPre,iNext;
if(pages<=1)%20iPre=1;
else%20iPre=pages%20-%201;%20%20

if(pages>=totalpages)%20iNext=totalpages;
else%20iNext=pages%20+%201;%20%20

int%20n=(int)(count/pagesize);
if(n*pagesizeif(n>1)
{
//for(i=1;i<=n;i++)
out.print(“”+i+”>”+i+””);
//out.print(“


“>”);
String%20lt1=”返回主页”,lt2=”第一页”,lt3=”上一页”,lt4=”下一
页”,lt5=”最后一页”,lt6=””;
lt6=””+%20lt1%20+%20″
a>”+
lurlt%20+%20″pages=”+iFirst+”>”+lt2+”&nbs
p;”+
lurlt%20+%20″pages=”+iPre+”>”+lt3+”
“%20+
lurlt%20+%20″pages=”+iNext+”>”+lt4+”
;%20″%20+
lurlt%20+%20″pages=”+iLast+”>”+lt5+”
;%20″;
st=””+

0%20width=”95%”>%20″+

00%”>”+
lt6+

“;%20%20

out.print(st);%20%20

}%20%20

}
}%20catch%20(Exception%20e)%20{%20out.println(“error:%20″+e);%20}
}%20%20

%>%20%20

//留言板界面尾部
String%20lbottom=””;
lbottom=lbottom+
“%20n”+

n”+
“%20n”+
“%20n”+

n”+%20%20

n”+

n”+

color=blue%20n”+
“%20face=楷体_GB2312%20size=5>发%20表%20意%20见
%20&nbs
p;%20[加*的内容必须填写]

n”+

n”+

n”+

n”+

永利集团304com,n”+

n”+

n”+

*留言主题:ame=lw_title%20n”+
“%20size=36>

n”+

n”+

*网上大名:ame=lw_author%20n”+
“%20size=36>

n”+

n”+

主页标题:=40%20name=pagetitle%20n”+
“%20size=36>

n”+

n”+

主页地址:=255%20name=author_http%20n”+
“%20size=36>

n”+

n”+

*电子邮件:ame=author_email%20n”+
“%20size=36>

n”+

n”+

n”+

n”+

n”+

n”+

请在下面填写你的留言:

n”+%20%20

n”+

7>

n”+

n”+

表情n”+
“%20″%20alt=”1.gif%20(152%20bytes)”%20height=15%20src=”1.gif”%20width=15>
NPUT%20n”+
“%20name=gifface%20type=radio%20value=2>height=15%20n”+
“%20src=”2.gif”%20width=15>%20>”%20alt=”3.gif%20(147%20bytes)”
height=15%20src=”3.gif”%20width=15>%20
NPUT%20n”+
“%20name=gifface%20type=radio%20value=4>height=15%20n”+
“%20src=”4.gif”%20width=15>%20>”%20alt=”5.gif%20(118%20bytes)”
height=15%20src=”5.gif”%20width=15>%20NPUT%20n”+
“%20name=gifface%20type=radio%20value=6>height=15%20n”+
“%20src=”6.gif”%20width=15>%20>”%20alt=”7.gif%20(180%20bytes)”
height=15%20src=”7.gif”%20width=15>%20
NPUT%20n”+
“%20name=gifface%20type=radio%20value=8>height=15%20n”+
“%20src=”8.gif”%20width=15>%20>”%20alt=”9.gif%20(162%20bytes)”
height=15%20src=”9.gif”%20width=15>%20NPUT%20n”+
“%20name=gifface%20type=radio%20value=10>”%20height=15%20n”+
“%20src=”10.gif”%20width=15>%2011>”%20alt=”11.gif%20(93%20bytes)”
height=15%20src=”11.gif”%20width=15>%20<
INPUT%20n”+
“%20name=gifface%20type=radio%20value=12>%20)”%20height=14%20n”+
“%20src=”12.gif”%20width=15>%20n”+
“%20″%20name=gifface%20type=radio%20value=13>%20)”%20height=14%20n”+
“%20src=”13.gif”%20width=15>%20n”+
“%20″%20name=gifface%20type=radio%20value=14>%20)”%20height=14%20n”+
“%20src=”14.gif”%20width=15>%20n”+
“%20″%20name=gifface%20type=radio%20value=15>%20)”%20height=14%20n”+
“%20src=”15.gif”%20width=15>%20n”+
“%20″%20name=gifface%20type=radio%20value=16>%20)”%20height=14%20n”+
“%20src=”16.gif”%20width=15>**

n”+

n”+

n”+

turn%20ValidInput()”%20type=submit%20value=”提%20交”>%20n”+%20%20

“%20e=”预%20览”>%20n”+
“%20T%20name=cmdBack%20onclick=javascript:history.go(-1)%20type=button
value=”返
回”>%20n”+

“;
out.print(lbottom);%20%20

%>%20%20

发表评论

电子邮件地址不会被公开。 必填项已用*标注