您的位置:首页网页设计JSP实例 → jsp留言板源代码二: 给jsp初学者.

jsp留言板源代码二: 给jsp初学者.

时间:2004/11/7 3:38:00来源:本站整理作者:蓝点我要评论(0)

作 者: precom (皮蛋) 2000.12.10



guestbook.jsp

===========================







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













<%@ page contentType="text/html; charset=GB2312" %>

<%@ page language="java" import="java.sql.*" %>



<%

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="


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=" ";

out.print(ljs);

%>



<%

//留言板界面首部

String ltop="
\n"+

"
\n"+

"
\n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"

+

" \n"+

" \n"+

"
\n"+

"


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

主页:
" href=\"http://www.zj.hn.cn\" target=_blank>
" color=#ffffff>张家界旅游
管理员:
+

" href=\"mailto:dzx@mail.zj.hn.cninfo.net\">

一民
\n"+

" >>
" href=\"http://www.zj.hn.cn \">
" color=#ffffff>管理
>>
" href=\" http://www.zj.hn.cn \">
" color=#ffffff>申请

r>
ue=\"搜 索\"> \n"+

"
\n"+

"
\n"+

"
";

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+"
" );

out.println(countsql);

}



totalpages=(int)(count/pagesize);

if(count>totalpages*pagesize) totalpages++;

st=""+

"
0 width=\"95%\"> "+

"

00%\">"+

" 共 "+totalpages+" 页,"+count+"

条. "+" 当前页: "+pages+

"

";



out.print(st);



//out.print(" 共 "+totalpages+" 页,"+

count+" 条. "+" 当前页: "+pages+"
");



st="
"+

" "+

" "+

" "+

" "+

" "+

" "+

" "+

" ";

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=" \n" +

" "+

" "+

" "+

" "+

" ";



out.println(linestr);



}

rs.close();

//显示第pages页结束

st="

" color=#ffffff>留言主题

" color=#ffffff>回应数

" color=#ffffff>点击数

" color=#ffffff>作者名

" color=#ffffff>发表/回应时间

">
" href=\""+llink+" \">"+lw_title+"
["+answer_num+"]"+click_num+"
il+"\">"+lw_author+"
"+st+"

";

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
if(n>1)

{

//for(i=1;i<=n;i++) out.print("

"+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%\"> "+

"

00%\">"+

lt6+

"

";



out.print(st);



}



}

} catch (Exception e) { out.println("error: "+e); }

}





%>





<%

//留言板界面尾部

String lbottom="";

lbottom=lbottom+

" \n"+

"
\n"+

" \n"+

" \n"+

" \n"+



" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

"

color=blue \n"+

" face=楷体_GB2312 size=5>发 表 意 见
&nbs

p; [加*的内容必须填写]
\n"+

"
\n"+

"

\n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

" \n"+

"
*留言主题:
ame=lw_title \n"+

" size=36>
*网上大名:
ame=lw_author \n"+

" size=36>
主页标题:
=40 name=pagetitle \n"+

" size=36>
主页地址:
=255 name=author_http \n"+

" size=36>
*电子邮件
ame=author_email \n"+

" size=36>
\n"+

"
\n"+

"

\n"+

" \n"+

" \n"+

" \n"+



" \n"+

"
请在下面填写你的留言:
表情\n"+

"
" alt=\"1.gif (152 bytes)\" height=15 src=\"1.gif\" width=15>
NPUT \n"+

" name=gifface type=radio value=2>\"2.gif
height=15 \n"+

" src=\"2.gif\" width=15>
>
" alt=\"3.gif (147 bytes)\" height=15 src=\"3.gif\" width=15>
NPUT \n"+

" name=gifface type=radio value=4>\"4.gif
height=15 \n"+

" src=\"4.gif\" width=15>
>
" alt=\"5.gif (118 bytes)\" height=15 src=\"5.gif\" width=15>
NPUT \n"+

" name=gifface type=radio value=6>\"6.gif
height=15 \n"+

" src=\"6.gif\" width=15>
>
" alt=\"7.gif (180 bytes)\" height=15 src=\"7.gif\" width=15>
NPUT \n"+

" name=gifface type=radio value=8>\"8.gif
height=15 \n"+

" src=\"8.gif\" width=15>
>
" alt=\"9.gif (162 bytes)\" height=15 src=\"9.gif\" width=15>
NPUT \n"+

" name=gifface type=radio value=10>\"10.gif
\" height=15 \n"+

" src=\"10.gif\" width=15>
11>
" alt=\"11.gif (93 bytes)\" height=15 src=\"11.gif\" width=15> <

INPUT \n"+

" name=gifface type=radio value=12> \"12.gif
)\" height=14 \n"+

" src=\"12.gif\" width=15> \n"+

"
" name=gifface type=radio value=13> \"13.gif
)\" height=14 \n"+

" src=\"13.gif\" width=15> \n"+

"
" name=gifface type=radio value=14> \"14.gif
)\" height=14 \n"+

" src=\"14.gif\" width=15> \n"+

"
" name=gifface type=radio value=15> \"15.gif
)\" height=14 \n"+

" src=\"15.gif\" width=15> \n"+

"
" name=gifface type=radio value=16> \"16.gif
)\" height=14 \n"+

" src=\"16.gif\" width=15>

turn ValidInput()\" type=submit value=\"提 交\"> \n"+



"
e=\"预 览\"> \n"+

"
T name=cmdBack onclick=javascript:history.go(-1) type=button value=\"返

回\"> \n"+

"
";

out.print(lbottom);



%>






相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 没有查询到任何记录。 学习java必学的几门技术jspSmartUpload上传下载全攻略Tomcat5.x中的虚拟主机配置方法利用iText在JSP中生成PDF报表

人气排行 告诉大家JSP连接数据库程序代码JSP单页面网站文件管理器jsp留言板源代码一: 给jsp初学者.在jsp中用bean和servlet联合实现用户注册、使用JSP + JAVABEAN + XML 开发的一个例子jsp在线考试系统-jsp文件 jsp计数器代码JSP/JAVABEAN+TOMCAT4.0.5+MYSQL组合建站总