您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
jsp留言板源代码三: 给jsp初学者.
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:26:41
作 者: precom (皮蛋) 2000.12.10
reply.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="",updatesql="",lwhere="",insertsql="",st=
"";

String lw_title="",lw_author="",pagetitle="",author_http="",author_e
mail="",lw_ico="0",
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=reply.jsp?";

lwhere=" where "; //只显示主贴

/*
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
*/
try{
//取显示的页页序数
pages = new Integer(request.getParameter("pages")).intValue();
} catch (Exception e) {}
try{
//取查询参数
lw_class1=new String(request.getParameter("lw_class1").getBytes
("ISO8859_1"));
lw_class2=new String(request.getParameter("lw_class2").getBytes
("ISO8859_1"));
zt_time=new String(request.getParameter("zt_time").getBytes("IS
O8859_1"));
zt_author=new String(request.getParameter("zt_author").getBytes
("ISO8859_1"));

lwhere=" where ( lw_class1='"+lw_class1+"' and lw_class2='"+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_class1="+lw_class1+"&lw_class2="+lw_class2+"&zt
_time="+zt_time+
"&zt_author="+zt_author+"&";
//out.print(lwhere);
} catch (Exception e) { //out.print("error1: "+e+"<hr>");
}

try{
//取得参数 留言内容
lw_class1=new String(request.getParameter("lw_class1").getBytes("ISO
8859_1"));
lw_class2=new 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")<0)
{ 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")<0)
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")<0)
out.print("msg="+st);
}catch (Exception e) { }
}
}catch (Exception e) { out.print("留言出错:"+e);}
} catch (Exception e) {}
%>

<%
//验证留言输入项合法性的javascript
String ljs=" <SCRIPT language=JavaScript> "+
" <!-- "+
" function ValidInput() "+
" {if(document.sign.lw_author.value=="") "+
" {alert("请填写您的大名。"); "+
" document.sign.lw_author.focus(); "+
" return false;} "+
" if(document.sign.lw_title.value=="") "+
" {alert("请填写留言主题。"); "+
" document.sign.lw_title.focus(); "+
" return false;} "+
" if (document.sign.author_email.value!="") "+
" { if ((document.sign.author_email.value.indexOf("@")<0)//(document
.sign.author_email.value.indexOf(":")!=-1)) "+
" {alert("您填写的EMail无效,请填写一个有效的Email!"); "+
" document.sign.author_emaill.focus(); "+
" return false; "+
" } "+
" } "+
" return true; "+
" } "+
" function ValidSearch() "+
" { if(document.frmsearch.findstr.value=="") "+
" {alert("不能搜索空串!"); "+
" document.frmsearch.findstr.focus(); "+
" return false;} "+
" } "+
" //--> "+
" </SCRIPT> ";
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")<0)
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+"<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%"><

[1] [2] [3] 下一页


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |