This section involves two pages, a donewuser.jsp file to implement a record to add actions, another file listuser.jsp file
Used to display all registered user information. Both the two pages involve the specific call of JavaBean, or to see the file,
For key code in the file, you will add a comment to make it easier for you.
DONEWUSER.JSP file
Description: User Registration Operations page, and displays the corresponding feedback according to the user registration, this page is mainly characterized by using
LYF.Adduser This JavaBean's AddNewuser () method is added to record.
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% response.setheader ("Expires", "0");%>
The correct attribute value, "*" represents the match of all attributes ->
hEAD>
<%
// Call the checkuser () method of lyf.adduser check if there is a duplicate username
// If there is a repetition, the corresponding information is displayed.
IF (! adduser.checkuser ())
{
// Page text output information, using the PrintLn method of the JSP built-in object OUT, equivalent to the response.write method in the ASP
Out.println ("Sorry, this username" adduser.getusername () "has been applied, please re-select!");
// Return represents return, and it will not perform the following processing when running. The function is equivalent to response.end in the ASP.
Return;
}
%>
<%
// If there is no user name repeated problem, call the LYF.AddUser's addNewUser () method to add user data to the database, and
Add success in accordance with data adding success No to display the corresponding information
IF (adduser.addnewuser ()) {
%>
Body>
Html>
Listuser.jsp file
Description: The User Information list page is used to display all user information registered, and the data is displayed.
In order to facilitate everyone to use, a general paging code is used, if it is JDBC2.0 or more other support
The database driver of the Type_Scroll_Insensitive cursor can have a more concise paging method.
And the statement similar to the previous JSP page does not explain, representing
This page is imported into this class library of java.sql.resultset because the RESULTSET should be declared in the middle of the JSP page;
Oracle.jdbc.driver. * Class library is an Oracle-specific JDBC driver that allows the JSP page to operate Oracle's database operations.
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% response.setheader ("Expires", "0");%>
<% @ Page Import = "java.sql.resultset"%>
<% @ Page Import = "Oracle.jdbc.driver. *"%>
<%
Java.lang.string strsql; // sql statement
INT INTPAGESIZE; / / One page shows the number of records
INT INTROWCOUNT; // Total number of records
INT INTPAGECUNT; / / Total number of pages
INT INTPAGE; // Waiting page number
Java.lang.string strpage;
INT I, J, K;
/ / Set the number of records displayed
INTPAGESIZE = 15;
/ / Get the page number to be displayed
StrPage = Request.getParameter ("Page");
if (strpage == null) {// Indicates that there is no Page in querystring, and the first page is displayed.
INTPAGE = 1;
}
Else {/ converts strings into integers
INTPAGE = java.lang.integer.parseint (STRPAGE);
IF (INTPAGE <1) INTPAGE = 1;
}
// Get the total number of records
strsql = "SELECT Count (*) from User";
ResultSet Result = db.executeQuery (strsql); // Execute SQL statement and acquire results set
Result.next (); // When the record is just opened, the pointer is before the first record.
introwcount = result.get.Getint (1); result.close (); // Close result set
// Mode total page
INTPAGECOUNT = (Introwcount INTPAGESIZE-1) / INTPAGESIZE
// Adjust the page number to be displayed
IF (INTPAGECOUNT) INTPAGE = INTPAGECOUNT
strsql = "SELECT * from user order by id";
/ / Execute the SQL statement and get the result set
Result = db.executeQuery (strsql);
// Position the record pointer to the first record of the page to be displayed
I = (INTPAGE-1) * INTPAGESIZE;
For (j = 0; J
hEAD>