JSP Message Board source code two: to JSP beginners. _JSP Programming

Source: Internet
Author: User
Author: precom (preserved egg) 2000.12.10





guestbook.jsp


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


<html><head>


<meta content= "text/html; charset=gb2312 "http-equiv=content-type>





<title> Zhangjiajie Telephone Yellow Pages (online 114) </title></head>


<style type= "Text/css" >


<!--


Body {font-family: "XXFarEastFont-Arial", "narrow", "Times New Roman"; Font-si


ZE:9PT}


. p1 {font-family: "XXFarEastFont-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: "Song Body", "Arial narrow", "Times New Roman"; Font-size


: 9pt}


. p2 {font-family: "XXFarEastFont-Arial", "narrow", "Times New Roman"; Font-siz


e:9pt; line-height:150%}


. p3 {font-family: "XXFarEastFont-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 '"; Show only main paste





/*


Enumeration E = Request.getparameternames ();


while (E.hasmoreelements ()) {


String name = (string) e.nextelement ();


*/


try{


Take the page ordinal that appears


pages = new Integer (Request.getparameter ("pages")). Intvalue ();


catch (Exception e) {}


try{


Fetch query Parameters


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{


Get parameter message content


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 ("illegal operation!");


Return


}





form other data items


Author_ip=request.getremoteaddr ();


Lw_time=testinq.getcurrentdate ("Yyyymmddhhmmss");


Lw_class2= "2";


Lw_type= "" + "Z"; Main paste


Zt_time=lw_time;


Zt_author=lw_author;


answer_num=0;


click_num=0;


//================


St= "', '";


Guarantee the length of all data items within the normal range


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


Insert Message


try{


String lmsg=testinq.executeupdate (Insertsql);


if (Lmsg.indexof ("executeupdate OK") <0)


Out.print ("lmsg=" +lmsg);





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


catch (Exception e) {}


%>





<%


JavaScript to validate message entry legality


String ljs= "<script language=javascript> \ n" +


"<!--\ n" +


"Function validinput () \ n" +


' {if (document.sign.lw_author.value==\ ' \ ') \ n ' +


"{alert (\) Please fill in your name." \"); \ n "+


"Document.sign.lw_author.focus (); \ n "+


"Return false;} \ n "+


"If" (document.sign.lw_title.value==\ "\") \ n "+


"{alert (\) Please fill in the message topic." \"); \ n "+


"Document.sign.lw_title.focus (); \ n "+


"Return false;} \ n "+


"If" (document.sign.author_email.value!=\ "\") \ n "+


"{if (Document.sign.author_email.value.indexOf (\" @\ ") <0)//(document


. Sign.author_email.value.indexOf (\ ": \")!=-1) \ n "+


"{alert (\" The email you filled out is invalid, please fill in a valid email!\ "); \ n" +


"Document.sign.author_emaill.focus (); \ n "+


"Return false; \ n "+


"} \ n" +


"} \ n" +


"Return true; \ n "+


"} \ n" +


"Function Validsearch () \ n" +


' {if (document.frmsearch.findstr.value==\ ' \ ') \ n ' +


"{alert (\" Cannot search for empty strings!) \"); \ n "+


"Document.frmsearch.findstr.focus (); \ n "+


"Return false;} \ n "+


"} \ n" +


"//--> \ n" +


"</SCRIPT>";


Out.print (LJS);


%>





<%


Message Board Interface Header


String ltop= "<div align=center> \ n" +


"<CENTER> \ n" +


"<form action=guestbook.jsp method=post name=frmsearch> \ n" +


"<input name=gbname Type=hidden value=cnzjj_gt> \ n" +


"<table align=center border=0 cellspacing=1 width=\" 95%\ "> \ n" +


"<TBODY> \ n" +


"<TR> \ n" +


"<td bgcolor= #336699 colspan=2 width=\" 100%\ "> \ n" +


"<p Align=center><font color= #ffffff face= italics _gb2312 \ n" +


"Size=5> welcome friends from afar to Zhangjiajie sightseeing </FONT></P></TD></TR> \ n"


+


"<tr bgcolor= #6699cc > \ n" +


"<td align=left noWrap width=\" 50%\ "> Home: <a \ n" +


"Href=\" http://www.zj.hn.cn\ "Target=_blank><font \ n" +


"Color= #ffffff > Zhangjiajie Tourism </FONT></A> admin: <a \ n"


+


"Href=\" mailto:dzx@mail.zj.hn.cninfo.net\ "><font color= #ffffff >


One min </FONT></A> \ n "+


">><a \ n" +


"Href=\" http://www.zj.hn.cn \ "><font \ n" +


"Color= #ffffff > Management </FONT></A> >><a \ n" +


"Href=\" http://www.zj.hn.cn \ "><font \ n" +


"Color= #ffffff > Application </FONT></A> </TD> \ n" +


"<td align=right width=\" 50%\ "><select Class=ourfont name=range S


ize=1> \ n "+


"<option selected value=0> by theme </OPTION> <option Value=1> Press


Rong </OPTION> \ n "+


"<option value=2> by author </OPTION> <option value=3> by Date </opti


On> <option \ n "+


"Value=4> by Theme & content </OPTION></SELECT> <input NAME=FINDST


r> <input name=search onclick=\ "return Validsearch () \" Type=submit Val


ue=\ "search \ > \ n" +


"</TD></TR></TBODY></TABLE></FORM> \ n" +


"<hr align=center noshade size=1 width=\" 95%\ "> \ n" +


"</CENTER></div>";


Out.print (ltop);


%>





<%


Show a page message in recent time


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


"A total of" +totalpages+ "page," +count+ "


Article. "+" Current page: "+pages+


"</FONT></TD></TR></TBODY></TABLE><BR>";





Out.print (ST);





Out.print ("Total" +totalpages+ "page," +


count+ "" + "Current page:" +pages+ "<br>");





St= "<center>" +


"<table border=0 cellpadding=2 cellspacing=1 width=\" 95%\ ">" +


"<TBODY>" +


"<TR>" +


"<td align=middle bgcolor= #6699cc width=\" 55%\ "><font" +


"Color= #ffffff > Message Theme </FONT></TD>" +


"<td align=middle bgcolor= #6699cc width=50><font" +


"Color= #ffffff > Response </FONT></TD>" +


"<td align=middle bgcolor= #6699cc width=40><font" +


"Color= #ffffff > clicks </FONT></TD>" +


"<td align=middle bgcolor= #6699cc width=100><font" +


"Color= #ffffff > Author name </FONT></TD>" +


"<td align=middle bgcolor= #6699cc width=140><font" +


"Color= #ffffff > Release/Response time </FONT></TD></TR>";


Out.print (ST);





if (Count > 0)


{


ResultSet rs = testinq.executequery (inqsql);


ResultSetMetaData metaData = Rs.getmetadata ();





int i;


Skip Pages-1 page, make cursor point to pages and prepare to display


For (i=1;i<= (pages-1) *pagesize;i++) Rs.next ();


Show Pages page start


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= "<tr bgcolor= #d5e8fd > \ n" +


"<td bgcolor= #d5e8fd ><img src=\" "+lw_ico+". gif\


"><a" +


"Href=\" "+llink+" \ ">" +lw_title+ "</A></TD>" +


"<td align=middle>[" +answer_num+ "]</td>" +


"<td align=middle>" +click_num+ "</TD>" +


"<td align=middle><a href=\" mailto: "+author_ema


il+ "\" > "+lw_author+" </A></TD> "+


"<td align=middle>" +st+ "</TD></TR>";





Out.println (LINESTR);





}


Rs.close ();


Show Pages page End


St= "</TBODY></TABLE><BR>";


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<count) n++;


if (n>1)


{


for (i=1;i<=n;i++) out.print ("<a href=inquire.jsp?pages=


"+i+" > "+i+" </a>);


Out.print ("<hr align=center noshade size=1 width=\" 95%\


">");


String lt1= "Back to Home", lt2= "first page", lt3= "prev", lt4= "next


Page ", lt5=" last page ", lt6=" ";


lt6= "<a href=http://www.zj.hn.cn>" + LT1 + "</


A> "+


LURLT + "pages=" +ifirst+ "><font color=red>" +lt2+ "&nbs"


P </a> "+


LURLT + "pages=" +ipre+ "><font color=red>" +lt3+ "


</a> "+


LURLT + "pages=" +inext+ "><font color=red>" +lt4+ "


; </a> "+


LURLT + "pages=" +ilast+ "><font color=red>" +lt5+ "


; </a> ";


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


lt6+


"</FONT></TD></TR></TBODY></TABLE><BR>";





Out.print (ST);





}





}


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


}








%>








<%


Message Board Interface Tail


String lbottom= "";


lbottom=lbottom+


"\ n" +


"<form action=guestbook.jsp method=post name=sign> \ n" +


"<input name=gbname Type=hidden value=cnzjj_gt> \ n" +


"<input name=pages Type=hidden value=1> \ n" +


"<table bgcolor= #d5e8fd border=0 cellspacing=1 width=\" 95%\ "> \ n" +





"<TBODY> \ n" +


"<TR> \ n" +


"<td align=middle bgcolor= #e6e6fa colspan=2 Nowrap><strong><font


Color=blue \ n "+


"face= italics _gb2312 size=5> comments </FONT></STRONG> &nbs


P [Add * content must be filled in] </TD></TR> \ n "+


"<TR> \ n" +


"<td noWrap width=\" 45%\ "> \ n" +


"<div align=left> \ n" +


"<table bgcolor= #d5e8fd border=0 cellspacing=1 width=\" 100%\ ">


\ n "+


"<TBODY> \ n" +


"<TR> \ n" +


"<td noWrap width=\" 100%\ ">* message topic: <input maxlength=40 N


Ame=lw_title \ n "+


"Size=36></td></tr> \ n" +


"<TR> \ n" +


"<td noWrap width=\" 100%\ ">* online name: <input maxlength=18 N


Ame=lw_author \ n "+


"Size=36></td></tr> \ n" +


"<TR> \ n" +


"<td noWrap width=\" 100%\ "> Home page title: <input maxLength


=40 name=pagetitle \ n "+


"Size=36></td></tr> \ n" +


"<TR> \ n" +


"<td noWrap width=\" 100%\ "> Home address: <input maxLength


=255 name=author_http \ n "+


"Size=36></td></tr> \ n" +


"<TR> \ n" +


"<td noWrap width=\" 100%\ >* Email: <input maxlength=40 N


Ame=author_email \ n "+


"Size=36></td></tr></tbody></table></div></td> \ n" +


"<td noWrap valign=top width=\" 55%\ "> \ n" +


"<div align=left> \ n" +


"<table bgcolor= #b6d7fc border=0 cellspacing=1 width=\" 100%\ ">


\ n "+


"<TBODY> \ n" +


"<TR> \ n" +


"<td width=\" 100%\ "> Please fill in your message below:</td></tr> \ n" +





"<TR> \ n" +


"<td width=\" 100%\ "><textarea cols=50 name=lw_content rows=


7></textarea></td></tr></tbody></table></div></td></tr> \ n "+


"<TR> \ n" +


"<td bgcolor= #fbf7ea colspan=2 nowrap> expression \ n" +


"<input name=gifface type=radio value=1 checked><img \ n" +


"Alt=\" 1.gif (152 bytes) \ height=15 src=\ "1.gif\" width=15> <i


Nput \ n "+


"Name=gifface type=radio value=2><img alt=\" 2.gif (174 bytes) \ "


HEIGHT=15 \ n "+


"Src=\" 2.gif\ "width=15> <input name=gifface type=radio value=3


><IMG \ n "+


"Alt=\" 3.gif (147 bytes) \ height=15 src=\ "3.gif\" width=15> <i


Nput \ n "+


"Name=gifface type=radio value=4><img alt=\" 4.gif (172 bytes) \ "


HEIGHT=15 \ n "+


"Src=\" 4.gif\ "width=15> <input name=gifface type=radio value=5


><IMG \ n "+


"Alt=\" 5.gif (118 bytes) \ height=15 src=\ "5.gif\" width=15> <i


Nput \ n "+


"Name=gifface type=radio value=6><img alt=\" 6.gif (180 bytes) \ "


HEIGHT=15 \ n "+


"Src=\" 6.gif\ "width=15> <input name=gifface type=radio value=7


><IMG \ n "+


"Alt=\" 7.gif (180 bytes) \ height=15 src=\ "7.gif\" width=15> <i


Nput \ n "+


"Name=gifface type=radio value=8><img alt=\" 8.gif (bytes) \ "


HEIGHT=15 \ n "+


"Src=\" 8.gif\ "width=15> <input name=gifface type=radio value=9


><IMG \ n "+


"Alt=\" 9.gif (162 bytes) \ height=15 src=\ "9.gif\" width=15> <i


Nput \ n "+


"Name=gifface type=radio value=10><img alt=\" 10.gif (113 bytes)


\ "height=15 \ n" +


"Src=\" 10.gif\ "width=15> <input name=gifface type=radio value=


11><IMG \ n "+


"alt=\" 11.gif (bytes) \ "height=15 src=\ 11.gif\" Width=15> <


INPUT \ n "+


"Name=gifface type=radio value=12> <img alt=\" 12.gif (149 bytes


) \ "height=14 \ n" +


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


"<input \ n" +


"Name=gifface type=radio value=13> <img alt=\" 13.gif (149 bytes


) \ "height=14 \ n" +


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


"<input \ n" +


"Name=gifface type=radio value=14> <img alt=\" 14.gif (149 bytes


) \ "height=14 \ n" +


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


"<input \ n" +


"Name=gifface type=radio value=15> <img alt=\" 15.gif (149 bytes


) \ "height=14 \ n" +


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


"<input \ n" +


"Name=gifface type=radio value=16> <img alt=\" 16.gif (149 bytes


) \ "height=14 \ n" +


"Src=\" 16.gif\ "width=15> </TD> \ n" +


"</TR> \ n" +


"<TR> \ n" +


"<td align=middle colspan=2 nowrap><input name=cmdgo onclick=\" re


Turn validinput () \ "Type=submit value=\" submit \ "> \ n" +





"<input name=cmdprev onclick=\" return validinput () \ Type=submit Valu


E=\ "preview \ > \ n" +


"<input name=cmdcancel type=reset value=\" rewrite \ "> <inpu


T name=cmdback onclick=javascript:history.go ( -1) Type=button value=\ "return


Back \ "> \ n" +


"</TD></TR></TBODY></TABLE></FORM></CENTER></DIV>";


Out.print (Lbottom);





%>





</body></html>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.