1. Create an oracle data table.
Create table guestbook (
Lw_title varchar2 (100) not null, -- Message Subject
Lw_author varchar2 (20) not null, -- the online name pk
Author_http varchar2 (40), -- home address
Author_email varchar2 (40) not null, -- email pk
Expression varchar2 (2) not null, -- expression
Lw_time varchar2 (14) not null, -- Post Response Time
Answer_num number (3) not null, -- number of responses
Click_num number (4) not null, -- number of clicks
Author_ip varchar2 (16), -- Source ip
Lw_class1 varchar2 (10) not null, -- main type of message board pk
Lw_class2 varchar2 (20) not null, -- forum topic pk
Lw_type varchar2 (1) not null, -- message category, that is, whether the main post
Zt_time varchar2 (14), -- post time
Zt_author varchar2 (40), -- Post email
Lw_content varchar2 (4000), -- Content
Constraint pk_guestbook primary key (lw_class1, lw_class2, lw
_ Time, lw_author)
) Storage (initial 5 M next 5 M pctincrease 1 );
Ii. guestbook. jsp
======================================
& Lt html & gt & lt head & gt
& Lt META content = "text/html; charset = gb2312" http-equiv = Content-Type & gt
& Lt title & gt Zhangjiajie Yellow Pages (114 on the Internet) & lt/title & gt & lt/head & gt
& Lt style type = "text/css" & gt
& Lt! --
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%}
-- & Gt
& Lt/style & gt
& Lt body & gt
& Lt % @ page contentType = "text/html; charset = GB2312" % & gt
& Lt % @ page language = "java" import = "java. SQL. *" % & gt
& Lt jsp: useBean id = "testInq" scope = "page" class = "ymbean. opDb"/& gt
& Lt %
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 = "& lt a href = guestbook. jsp? ", Llink = "";
Lwhere = "where lw_type = z"; // 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
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") & lt 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"; // post
Zt_time = lw_time;
Zt_author = lw_author;
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 () & gt50) lw_title = lw_title.substring (0, 50 );
If (lw_author.length () & gt20) lw_author = lw_author.substring (0, 20 );
If (author_http.length () & gt40) author_http = author_http.substring (0, 40 );
If (author_email.length () & gt50) author_email = author_email.substring (0, 4
0 );
If (lw_content.length () & gt4000) 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 a message
Try {
String lmsg=testInq.exe cuteUpdate (insertsql );
If (lmsg. indexOf ("executeUpdate OK") & lt 0)
Out. print ("lmsg =" + lmsg );
} Catch (Exception e) {out. print ("error:" + e );}
} Catch (Exception e ){}
% & Gt
& Lt %
// Verify the validity of the entered message.
String ljs = "& lt SCRIPT language = JavaScript & gt" +
"& Lt! -- "+
"Function ValidInput ()" +
"{If (document. sign. lw_author.value =" ")" +
"{Alert (" enter your name. ");" +
"Document. sign. lw_author.focus ();" +
"Return false;}" +
"If (document. sign. lw_title.value =" ")" +
"{Alert (" Enter the message subject. ");" +
"Document. sign. lw_title.focus ();" +
"Return false;}" +
"If (document. sign. author_email.value! = "") "+
"{If (document. sign. author_email.value.indexOf (" @ ") & lt 0) // (document
. Sign. author_email.value.indexOf (":")! =-1) "+
"{Alert (" the EMail you entered is invalid. Please enter a valid Email! ");" +
"Document. sign. author_emaill.focus ();" +
"Return false;" +
"}" +
"}" +
"Return true;" +
"}" +
"Function ValidSearch ()" +
"{If (document. frmsearch. findstr. value =" ")" +
"{Alert (" Empty strings cannot be searched! ");" +
"Document. frmsearch. findstr. focus ();" +
"Return false;}" +
"}" +
"// -- & Gt" +
"& Lt/SCRIPT & gt ";
Out. print (ljs );
% & Gt
& Lt %
// Message board interface Header
String ltop = "& lt DIV align = center & gt" +
"& Lt CENTER & gt" +
"& Lt FORM action = guestbook. jsp method = post name = frmsearch & gt" +
"& Lt INPUT name = gbname type = hidden value = cnzjj_gt & gt" +
"& Lt TABLE align = center border = 0 cellSpacing = 1 width =" 95% "& gt" +
"& Lt TBODY & gt" +
"& Lt TR & gt" +
"& Lt TD bgColor = #336699 colSpan = 2 width =" 100% "&