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

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


reply.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= "", 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"; 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


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{


Get parameter message content


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


Return


}





form other data items


Author_ip=request.getremoteaddr ();


Lw_time=testinq.getcurrentdate ("Yyyymmddhhmmss");


Lw_type= "" + "C"; From the Paste


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


Insert Message


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


Increase the number of respondents to the statistics


try{


St=testinq.executeupdate (Updatesql);


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


Out.print ("msg=" +st);


}catch (Exception e) {}


}


}catch (Exception e) {out.print ("message 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);


%>








<%


Show a page message in recent time


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;





Increase the number of visitors to the survey


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


"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


st= "<CENTER> <table border=0 cellspacing=1 width=\" 95%\ "


> <TBODY> ";


Out.print (ST);


String linestr= "";


for (i=1;i<=pagesize;i++)


if (Rs.next ())


{


Lw_title=rs.getstring ("Lw_title");


Lw_author=rs.getstring ("Lw_author");


Lw_time=rs.getstring ("Lw_time");


Lw_content=rs.getstring ("Lw_content");


Author_ip=rs.getstring ("Author_ip");


Author_email=rs.getstring ("Author_email");


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


TRY{LW_CONTENT=TESTINQ.ADDBR (Testinq.removecomment (Lw_co


ntent));} catch (Exception e) {}


Linestr = "" +


"<tr bgcolor= #bed9fc >" +


"<td align=left width=\" 75%\ "><font" +


"Color= #0000cd > Message Theme:</font><strong>"


+lw_title+ "</STRONG></TD>" +


"<td align=left width=\" 25%\ "><font color=


#0000cd > Message Time:</font> "+st+" </TD></TR> "+


"<tr bgcolor= #e7f1fe >" +


"<td colspan=2" +


"Width=\" 700\ "wrap=yes><br>" +lw_content+ "


<BR><br></TD></TR> "+


"<tr bgcolor= #bed9fc >" +


"<td align=right colspan=2 width=\" 100%\ ">


<font "+


"Color= #0000cd > Author:</font>" +lw_author+ "


<font "+


"Color= #0000cd > Source:</font>" +author_ip+ "


</TD></TR> ";


Out.println (LINESTR);





}


Rs.close ();


Show Pages page End


St= "</TBODY></TABLE></CENTER></DIV><BR>" +





"<center><a" +


"Href=\" guestbook.jsp\ "><font" +


"Color=blue face= italics _gb2312 size=4> return message board


Home </FONT></A></CENTER><BR> "+


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


> ";





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+


"<center> \ n" +


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


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


"<input name=lw_class2 type=hidden value=" +lw_class2+ "> \ n"


+


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


"<input name=zt_time type=hidden value=" +zt_time+ "> \ n" +


"<input name=zt_author type=hidden value=" +zt_author+ "> \ 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>





Author: precom (preserved egg) 2000.12.10


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.