一段用Java编写的留言板源代码(一)(二)

2014-11-23 22:32:33 · 作者: · 浏览: 1
("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) {}
% >

< %
//验证留言输入项合法性的java script
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%" &