您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
jsp留言板源代码二: 给jsp初学者.
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:26:40
作 者: 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> "+
" <!-- "+
" 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);
%>

<%
//留言板界面首部
String ltop=" <DIV align=center> "+
" <CENTER> "+
" <FORM action=guestbook.jsp method=post name=frmsearch> "+
" <INPUT name=gbname type=hidden value=cnzjj_gt> "+
" <TABLE align=center border=0 cellSpacing=1 width="95%"> "+
" <TBODY> "+
" <TR> "+
" <TD bgColor=#336699 colSpan=2 width="100%"> "+
" <P align=center><FONT color=#ffffff face=楷体_GB2312 "+
" size=5>欢迎远方的朋友来张家界旅游观光</FONT></P></TD></TR> "
+
" <TR bgColor=#6699cc> "+
" <TD align=left noWrap width="50%">主页: <A "+
" href="http://www.zj.hn.cn" target=_blank><FONT "+
" color=#ffffff>张家界旅游</FONT></A> 管理员: <A "
+
" href="mailto:dzx@mail.zj.hn.cninfo.net"><FONT color=#ffffff>
一民</FONT></A> "+
" >><A "+
" href="http://www.zj.hn.cn "><FONT "+
" color=#ffffff>管理</FONT></A> >><A "+
" href=" http://www.zj.hn.cn "><FONT "+
" color=#ffffff>申请</FONT></A> </TD> "+
" <TD align=right width="50%"><SELECT class=ourfont name=range s
ize=1> "+
" <OPTION selected value=0>按主题</OPTION> <OPTION value=1>按内
容</OPTION> "+
" <OPTION value=2>按作者</OPTION> <OPTION value=3>按日期</OPTI
ON> <OPTION "+
" value=4>按主题&内容</OPTION></SELECT> <INPUT name=findst
r> <INPUT name=search onclick="return ValidSearch()" type=submit val
ue="搜 索"> "+
" </TD></TR></TBODY></TABLE></FORM> "+
" <HR align=center noShade SIZE=1 width="95%"> "+
" </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

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


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