Jsp message board source code 3: for jsp beginners.

Source: Internet
Author: User

Prepared by: precom (pig) 2000.12.10
Reply. jsp
==========================================
<Html> <META content = "text/html; charset = gb2312" http-equiv = Content-Type>

<Title> Zhangjiajie Yellow Pages (114 on the Internet) </title> <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 = "", 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"; // only show the primary sticker

/*
Enumeration e = request. getParameterNames ();
While (e. hasMoreElements ()){
String name = (String) e. nextElement ();
*/
Try {
// Obtain the order number of the displayed pages
Pages = new Integer (request. getParameter ("pages"). intValue ();
} Catch (Exception e ){}
Try {
// Retrieve 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 + "}

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"; // slave post
Answer_num = 0;
Click_num = 0;
// ==========================
St = "','";
// Ensure that the length of all data items in the message is 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)

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 a message
Try {
St=testInq.exe cuteUpdate (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 replies
Try {
St=testInq.exe cuteUpdate (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 ){}
%>

<%
// Verify the validity of the entered message.
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 (\" Enter the message subject. \ "); \ 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 entered is invalid. Please enter 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 );
%>

<%
// Display a message posted last 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 browser count
Try {
St=testInq.exe cuteUpdate (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.exe cuteQuery (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% \" type = "codeph" text = "codeph"> "+
"<TBODY> <TR> <TD align = middle bgColor = #97 badd width = \" 1
00% \ "> <FONT color = # ff0000>" +
"Total" + totalpages + "page," + count +"
. "+" Current page: "+ pages +
"</FONT> </TD> </TR> </TBODY> </TABLE> <BR> ";

Out. print (st );

// Out. print ("Total" + totalpages + "page," +
Count + "entries." + "Current page:" + pages + "<br> ");

St = "<center>" +
& Quot; <TABLE border = 0 cellPadding = 2 cellSpacing = 1 width = \ & quot; 95% \ & quot;> & quot; +
"<TBODY>" +
"<TR>" +
"<TD align = middle bgColor = # 6699cc width = \" 55% \ "> <FONT" +
"Color = # ffffff> Message Subject </FONT> </TD>" +
"<TD align = middle bgColor = # 6699cc width = 50> <FONT" +
"Color = # ffffff> Response count </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> posting/response time </FONT> </TD> </TR> ";
// Out. print (st );

If (count> 0)
{
ResultSet rs = testInq.exe cuteQuery (inqsql );
ResultSetMetaData metaData = rs. getMetaData ();

Int I;
// Skip pages-1 to point cursor to pages and prepare to display
For (I = 1; I <= (pages-1) * pagesize; I ++) rs. next ();
// Display the beginning of pages
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 Subject: </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 ();
// Display page pages to end
St = "</TBODY> </TABLE> </CENTER> </DIV> <BR>" +

"<CENTER> <A" +
"Href = \" guestbook. jsp \ "> <FONT" +
"Color = blue face = _ GB2312 size = 4> return message board
Homepage </FONT> </A> </CENTER> <BR> "+
& Quot; <HR align = center noShade SIZE = 1 width = \ & quot; 95% \ & quot \"
> ";

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 homepage", lt2 = "first page", lt3 = "Previous Page", 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% \" type = "codeph" text = "codeph"> "+
"<TBODY> <TR> <TD align = middle bgColor = #97 badd width = \" 1
00% \ "> <FONT color = # ff0000>" +
Lt6 +
"</FONT> </TD> </TR> </TBODY> </TABLE> <BR> ";

Out. print (st );

}

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

%>

<%
// The End Of The message board interface
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 = _ GB2312 size = 5> For more information, see </FONT> </STRONG> & nbs.
P; [add * content required] </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 Subject: <INPUT maxLength = 40 n
Ame = lw_title \ n "+
"Size = 36> </TD> </TR> \ n" +
"<TR> \ n" +
"<TD noWrap width = \" 100% \ "> * Network Name: <INPUT maxLength = 18 n
Ame = lw_author \ n "+
"Size = 36> </TD> </TR> \ n" +
"<TR> \ n" +
"<TD noWrap width = \" 100% \ "> homepage 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% \ "> enter 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> emotion \ 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> 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> 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> 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> 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> \ "Height = 15 \ n" +
"Src = \" 10.gif \ "width = 15> <INPUT name = gifface type = radio value =
11> <IMG \ n "+
"Alt = \" 11.gif (93 bytes) \ "height = 15 src = \" 11.gif \ "width = 15> <
INPUT \ n "+
"Name = gifface type = radio value = 12> ) \ "Height = 14 \ n" +
"Src = \" 12.gif \ "width = 15> \ n" +
"<INPUT \ n" +
"Name = gifface type = radio value = 13> ) \ "Height = 14 \ n" +
"Src = \" 13.gif \ "width = 15> \ n" +
"<INPUT \ n" +
"Name = gifface type = radio value = 14> ) \ "Height = 14 \ n" +
"Src = \" 14.gif \ "width = 15> \ n" +
"<INPUT \ n" +
"Name = gifface type = radio value = 15> ) \ "Height = 14 \ n" +
"Src = \" 15.gif \ "width = 15> \ n" +
"<INPUT \ n" +
"Name = gifface type = radio value = 16> ) \ "Height = 14 \ n" +
"Src = \" 16.gif \ "width = 15> </TD> \ n" +
"</TR> \ n" +
"<TR> \ n" +
"<TD align = middle colSpan = 2 noWrap> <INPUT name = export go onclick = \" re
Turn ValidInput () \ "type = submit value = \" submit \ "> \ n" +

"<INPUT name = Your Prev onclick = \" return ValidInput () \ "type = submit valu
E = \ "preview \"> \ n "+
"<INPUT name = export cancel type = reset value = \" re-write \ "> <INPU
T name = cmdBack onclick = javascript: history. go (-1) type = button value = \ "back
Back to \ "> \ n" +
"</TD> </TR> </TBODY> </TABLE> </FORM> </CENTER> </DIV> ";
Out. print (lbottom );

%>

</Body>

Prepared by: precom (pig) 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.