jsp留言板源代码三: 给jsp初学者_MySQL
程序员文章站
2022-05-10 23:47:50
...
reply.jsp
====================================
张家界电话黄页(网上114)
int pages=1;
int pagesize=10;
lwhere=" where ( lw_'"+lw_
class2+
"' and (lw_time='"+ zt_time+"' or zt_time='"+zt_time+
"') and (author_email='"+zt_author+"' or zt_author='"+zt
_author+"') ) ";
lurlt=lurlt+"lw_"+lw_class2+"&zt
_time="+zt_time+
"&zt_author="+zt_author+"&";
//out.print(lwhere);
} catch (Exception e) { //out.print("error1: "+e+"
");
}
try{
//取得参数 留言内容
lw_ String(request.getParameter("lw_class1").getBytes("ISO
8859_1"));
lw_ String(request.getParameter("lw_class2").getBytes("ISO
8859_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"));
zt_time=new String(request.getParameter("zt_time").getBytes("ISO8859
_1"));
zt_author=new String(request.getParameter("zt_author").getBytes("ISO
8859_1"));
lw_ico=request.getParameter("gifface");
} catch (Exception e) {}
try{
lw_content=new String(request.getParameter("lw_content").getBytes("I
SO8859_1"));
String requestMethod=request.getMethod();
requestMethod=requestMethod.toUpperCase();
if(requestMethod.indexOf("POST") { out.print("非法操作!");
return;
}
//形成其他数据项
author_ip=request.getRemoteAddr() ;
lw_time=testInq.getCurrentDate("yyyyMMddHHmmss");
lw_type=""+"c"; //从贴
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(zt_author.length()>50) zt_author=zt_author.substring(0,40);
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{
st=testInq.executeUpdate(insertsql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
else
{
updatesql="update guestbook set answer_num=answer_num + 1 "+l
where;
//增加回复人数统计
try{
st=testInq.executeUpdate(updatesql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
}catch (Exception e) { }
}
}catch (Exception e) { out.print("留言出错:"+e);}
} catch (Exception e) {}
%>
//验证留言输入项合法性的javascript
String ljs=" ";
out.print(ljs);
%>
//显示最近时间发表的一页留言
countsql="select count(lw_title) from guestbook "+lwhere;
inqsql ="select lw_title,lw_author,lw_time,lw_content,author_ip, "+
" author_email from guestbook "+lwhere+" order by lw_time desc
" ;
updatesql="update guestbook set click_num=click_num + 1 "+lwhere;
//增加浏览人数统计
try{
st=testInq.executeUpdate(updatesql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
}catch (Exception e) { }
//out.print(inqsql);
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+"
" );
out.println(countsql);
}
totalpages=(int)(count/pagesize);
if(count>totalpages*pagesize) totalpages++;
st=""+
"
0 width=\"95%\"> "+
";
out.print(st);
//out.print(" 共 "+totalpages+" 页,"+
count+" 条. "+" 当前页: "+pages+"
");
st=" "+
" "+
"+
"
" href=\"guestbook.jsp\">
" color=blue face=楷体_GB2312 size=4>返回留言板
首页
"+
"
> ";
out.print(st);
int iFirst=1,iLast=totalpages,iPre,iNext;
if(pages else iPre=pages - 1;
if(pages>=totalpages) iNext=totalpages;
else iNext=pages + 1;
int n=(int)(count/pagesize);
if(n*pagesize
if(n>1)
{
//for(i=1;i "+i+">"+i+" ");
//out.print("
">");
String lt1="返回主页",lt2="第一页",lt3="上一页",lt4="下一
页",lt5="最后一页",lt6="";
lt6=""+ lt1 + "
a>"+
lurlt + "pages="+iFirst+">"+lt2+"&nbs
p; "+
lurlt + "pages="+iPre+">"+lt3+"
" +
lurlt + "pages="+iNext+">"+lt4+"
; " +
lurlt + "pages="+iLast+">"+lt5+"
; ";
st=""+
"
0 width=\"95%\"> "+
";
out.print(st);
}
}
} catch (Exception e) { out.println("error: "+e); }
}
%>
//留言板界面尾部
String lbottom="";
lbottom=lbottom+
" \n"+
" ";
out.print(lbottom);
%>
====================================
int pages=1;
int pagesize=10;
lwhere=" where ( lw_'"+lw_
class2+
"' and (lw_time='"+ zt_time+"' or zt_time='"+zt_time+
"') and (author_email='"+zt_author+"' or zt_author='"+zt
_author+"') ) ";
lurlt=lurlt+"lw_"+lw_class2+"&zt
_time="+zt_time+
"&zt_author="+zt_author+"&";
//out.print(lwhere);
} catch (Exception e) { //out.print("error1: "+e+"
");
}
try{
//取得参数 留言内容
lw_ String(request.getParameter("lw_class1").getBytes("ISO
8859_1"));
lw_ String(request.getParameter("lw_class2").getBytes("ISO
8859_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"));
zt_time=new String(request.getParameter("zt_time").getBytes("ISO8859
_1"));
zt_author=new String(request.getParameter("zt_author").getBytes("ISO
8859_1"));
lw_ico=request.getParameter("gifface");
} catch (Exception e) {}
try{
lw_content=new String(request.getParameter("lw_content").getBytes("I
SO8859_1"));
String requestMethod=request.getMethod();
requestMethod=requestMethod.toUpperCase();
if(requestMethod.indexOf("POST") { out.print("非法操作!");
return;
}
//形成其他数据项
author_ip=request.getRemoteAddr() ;
lw_time=testInq.getCurrentDate("yyyyMMddHHmmss");
lw_type=""+"c"; //从贴
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(zt_author.length()>50) zt_author=zt_author.substring(0,40);
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{
st=testInq.executeUpdate(insertsql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
else
{
updatesql="update guestbook set answer_num=answer_num + 1 "+l
where;
//增加回复人数统计
try{
st=testInq.executeUpdate(updatesql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
}catch (Exception e) { }
}
}catch (Exception e) { out.print("留言出错:"+e);}
} catch (Exception e) {}
%>
//验证留言输入项合法性的javascript
String ljs=" ";
out.print(ljs);
%>
//显示最近时间发表的一页留言
countsql="select count(lw_title) from guestbook "+lwhere;
inqsql ="select lw_title,lw_author,lw_time,lw_content,author_ip, "+
" author_email from guestbook "+lwhere+" order by lw_time desc
" ;
updatesql="update guestbook set click_num=click_num + 1 "+lwhere;
//增加浏览人数统计
try{
st=testInq.executeUpdate(updatesql);
if(st.indexOf("executeUpdate ok") out.print("msg="+st);
}catch (Exception e) { }
//out.print(inqsql);
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+"
" );
out.println(countsql);
}
totalpages=(int)(count/pagesize);
if(count>totalpages*pagesize) totalpages++;
st=""+
"
00%\">"+ " 共 "+totalpages+" 页,"+count+" 条. "+" 当前页: "+pages+ " |
";
out.print(st);
//out.print(" 共 "+totalpages+" 页,"+
count+" 条. "+" 当前页: "+pages+"
");
st="
"
" color=#ffffff>留言主题 | "+" color=#ffffff>回应数 | "+" color=#ffffff>点击数 | "+" color=#ffffff>作者名 | "+" color=#ffffff>发表/回应时间 |
" color=#0000cd>留言主题:" +lw_title+" | "+ #0000cd>留言时间:"+st+" |
" width=\"700\" wrap=yes> "+lw_content+" |
|
" color=#0000cd>作者:"+lw_author+" " color=#0000cd>来源:"+author_ip+" |
"+
"
首页
"+
"
> ";
out.print(st);
int iFirst=1,iLast=totalpages,iPre,iNext;
if(pages else iPre=pages - 1;
if(pages>=totalpages) iNext=totalpages;
else iNext=pages + 1;
int n=(int)(count/pagesize);
if(n*pagesize
{
//for(i=1;i "+i+">"+i+" ");
//out.print("
">");
String lt1="返回主页",lt2="第一页",lt3="上一页",lt4="下一
页",lt5="最后一页",lt6="";
lt6=""+ lt1 + "
a>"+
lurlt + "pages="+iFirst+">"+lt2+"&nbs
p; "+
lurlt + "pages="+iPre+">"+lt3+"
" +
lurlt + "pages="+iNext+">"+lt4+"
; " +
lurlt + "pages="+iLast+">"+lt5+"
; ";
st=""+
"
00%\">"+ lt6+ " |
";
out.print(st);
}
}
} catch (Exception e) { out.println("error: "+e); }
}
%>
//留言板界面尾部
String lbottom="";
lbottom=lbottom+
"
"
out.print(lbottom);
%>
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论