Pagination

xiaoxiao2021-03-06  93

http://www.tele21.com.cn/jiaoliu/show.asp?classid=747

B / S under the framework of joint action paged list boxes: vertical and horizontal software production center rain also odd SEOUL taken from a design joint action paged list boxes of reason in the development of dynamic Web sites under the B / S architecture, we often encounter Such a type of management nature, that is, select an object to add or delete one or more attributes or permissions for the object, such as the group user management of the system administrator, first select one group, and then you can Add some users in this group, or you can delete several users from this group. Another documentation is asked for documentation in document administrators, after selecting a document, you can add readers to this document, delete readers, and implement the management of documents to read crowds, who can watch, who can't see, wait Wait. Such a type of problem mode, I call the group user management mode. For group user management mode, the following method is usually solved: 1. Design main operations page (see Figure 1, manage as an example of group users); 2. Design addition, delete such auxiliary operation page, they all pass the main operation page Buttons to activate. The main operation page is generally divided into "set of groups", "users who are not in the current group" (that is, candidate users), "operation", and "user" in the current group "quad column. "Alternative group", "User in the current group" and "User in the current group" three columns are a SELECT list box, all data is placed in the list box for users to view or select. According to the selected group, "User in the current group" is also changed accordingly by the "user" in the current group ", so-called" linkage "is intended. Figure 1. Ordinary list box Demonstration page can be added to the current group without users in the current group; can also be removed by deleting the buttons: to remove some users in the current group, go to "user in the current group" column. For adding and deleting operations, the processing means of timely updating the database is used. Put all the data in the list box, this idea is simple, the amount of data is also very effective, but for the development of a dynamic website (especially large business sites), anyone must face such a major test: along with The time of time, the amount of data is gradually increased, and the page data generated by this is growing, the browser download page will be extended, the user's operation is not responding in time, making the user lose patience, so that the website is represented damage. How to do it? Only by finishing zero, on-demand access, use paging technology to solve: only one page of content is displayed at a time, if you want to see other pages, click on the page link. This implementation, the amount of page data is small, the response speed is fast, and it is very welcome. The specific implementation of paging technology, different people may use different methods, and I have been carefully studied, design successfully commonly used linkage paging list box, providing a perfect solution for paging issues in group user management mode. Second, the design linkage paging list box for the linkage paging list box (see Figure 2), simple form, effective operation. It is based on the normal list box, adding a row button on the right side to implement page page function. The button is used for forward pages for backwards. When the button is pressed, the corresponding flip function is prohibited by the system.

Figure 2. The linkage paging list box is paid on the list box, and the title is similar to the number of M / N in the title. It is "this column paging list box has n pages. The current display is the M-page", clear A paging information is represented. For example, the "optional group (1/2)" shown in Figure 2 indicates that a set of 2 pages is available, and is currently displayed on page 1. After clicking the "Optional Group" column, the list box content of this column changes accordingly to the previous page or next page. Due to the linkage, "user" in the current group "and" user "in the current group will change as the group changes. If the selected group does not change, the "user" in the current group "does not affect the contents of the other party's paging list box in the" user "in the current group, ie" users who are not in the current group "" When a column is turned on, the "The user" in the current group does not change, and when the "User" column in the "current group" is turned on, "The user in the current group" is displayed. It will not change. Through the linkage paging list box, the user can easily select the group, which is convenient to delete the user. For users that have deleted in this page, you need to take effect, you need to click the "Confirm" button to update the database. Because the operator may forget to change the "confirm" button after adding the deletion of the user, I want to turn the page directly. For the convenience, I also provide a confirmation prompt when I realize it. After confirmation, the program is automatically updated, Then automatically turn the page. Third, the linkage of the linkage paging list box is implemented by the program, which is the most popular JavaBean JSP technology implementation under the B / S architecture: the JavaBean class that is written in the Java language is written in the Java language, which is used for database operation and implementation paging. Write a dynamic web page with JSP (Java Server Pages) to display paging and responding to user operations. (Note: Detailed procedure is shown in the attachment. This article only briefs its intrinsic mechanism, which provides the Rose model of the JavaBean class program for easy users. Establishing the advantage of ROSE models, is intuitive, well-understood, and can use Rose tool to generate Java Code or related document.) (1) Javabean class 1, resultrow.java Figure 3, Resultrow model program parsing: ResulTrow Indicates a line of results in the query result, inherits the class of Hashtable, so it is easy to use Field names are to access their values. The GetValue method is provided in Resultrow for taking the corresponding value according to the specified field name. 2, queryResult.java Figure 4, QueryResult model program analysis: queryResult Indicates the entire query result set, its parent class is a vector (vectors), each of which is a resultrow result line. QueryResult provides a method of getRow, which can be used in accordance with the specified line number LINENO.

3, DBCON.JAVA Figure 5, DBCON model program analysis: DBCON is class used to deal with the database. From the model, it can see it has four private variables: 1 Host: The host where the WebLogic server is located, the default is "Localhost "2 Port: For the port used for the WebLogic server, the default value is" 7001 "; 3 Name: is the data source name, the default value is" Oracleds "; 4 Conf: This is a hash table for storage and database connection Configuration information. It is set during the static initialization of the class, and its data is shared throughout the class. Here is a static initialization code: static

{

CONF = new hashtable ();

Conf.put (Context.Initial_Context_Factory, "WebLogic.jndi.wlinitialContextFactory";

Conf.PUT (Context.Provider_URL, "T3: //" Host ":" port);

}

DBCON provides two universal database operations: one is query, the method is Runquery, the execution returns the queryResult query result set; the other is updated, the method is runupdate, the execution returned is a record line that is affected by the operation number. Both functions are performed according to the SQL statement provided by the user. DBCON uses a database connection pool built in the WebLogic server, and obtains a database connection with JNDI data source technology. The benefits of using the WebLogic server built-in pool: First, it is easy to manage, because WebLogic provides a function of connecting pools such as connecting pools through web pages; second, the program is simple and clear; the third is to significantly improve program performance. Please see the source program of the RunupDate method (the number in front of each line):

1 Public Static int Runupdate (String SQL) THROWS Exception

2 {

3 Context CTX = New InitialContext (conf);

4 DataSource DS = (Datasource) ctx.lookup (name);

5 Connection conn = ds.getConnection ();

6 statement stmt = conn.createstatement ();

7 int RC;

8 TRY

9 {

10 rc = stmt.executeUpdate (SQL);

11}

12 Catch (Exception EX)

13 {

14 throw new exception ("SQL: /" SQL "/" performs an error, because " ex.getMessage ());

15}

16 stmt.close ();

17 conn.close ();

18 ctx.close ();

19 RETURN RC;

20}

Note:

Third line: According to the CONF configuration information, it is initialized to get a JNDI context CTX. Chapter 4: A data source DS named NAME is obtained in the context CTX.

Chapter 5: A connection conn is obtained from the data source DS.

Chapter 6: Newly built a statement object STMT by the connection conn.

Chapter 10: Execute the user's SQL statement SQL.

Line 16-18: Turn off all resources.

Chapter 19: Returns the number of affected records RC.

4. QueryPage.Java Figure 6, QueryPage model program parsing: QueryPage is a class that is used to obtain paging data. It can be seen from the model that there are three private variables: 1 LINESPAGE: For each page number, default is 1. 2 Totalpages: The number of pages obtained after the query pagination is default 1. 3 Result: The result set returned to the query, default is NULL (empty). This class has three common methods: 1 init: query initialization, mainly calling DBCON's Runquery method, performs the SQL command provided by the user, and makes the query result pane processing. 2 isinit: Detect whether it has been initialized. 3 getPage: Return the page results row according to the page number provided by the user, the return value type is Resultrow [] (Result line array). 5, Utilities.java Figure 7, UTILITIES model program parsing: Utilities is a tool class, primarily to convert some conversions for the parameters obtained for JSP web pages (such as characters to digital, etc.) and do not throw any exceptions. This class has two methods: 1 TRIM: Used to remove the string before and after. When the string is NULL (empty), it will depend on "" (empty string). 2 ATOI: Used to convert a string into a number to ignore an exception that occurs during the conversion process. When there is an abnormality, the obtained number is default to zero. (2) JSP dynamic web 1, zhsoft.jsp This JSP file is used to display the content of the linkage paging list box, which is the main page. It receives the following parameters: 1 Group_ID: "The Group's ID (current group ID) selected in the" Setable Group "column. 2 Group_pageno: "The page number of the" Album Group "column (the list of collaboration boxes). 3 Candidate_pageno: "Not in the user" column page number (referred to as the candidate list box page number). 4 CURRENT_PAGENO: "The user" column in the current group (referred to as the current list box page number). 5 Apply_Flag: To confirm the update flag. This flag is passed by apply.jsp After updating the database, if the zhsoft.jsp gives it greater than 0, you need to reinitialize the query, update the main page. It also defines the following constant (the user can modify according to the actual situation): 1 Lines_Per_Page: Refers to the number of rows per page, for paging. 2 SELECT_LINES: Defines the height of the paging list box. 3 Column_Name_OF_Value: Defined the database field name corresponding to the value of the paging list box option. 4 column_name_of_label: Defined the database field name corresponding to the value of the paging list box option display. ZHSOFT.JSP has established four JavaBean instances: 1

2

3

4

The first is an instance of the Utilities tool class, the ID is U. The following three are the instances of the QueryPage class, and the IDs are Groups, Candidate, and Current, the query and pagination of the Cardios, the candidate list box, and the current list box. The process of zhsoft.jsp generates a dynamic page is: First receive parameters, determine if the parameter should be queried (ie, call the querypage init method, refresh the page data), then correct the column page number to prevent illegal page number Finally, take the data of the specified page number (ie, call the QueryPage's getPage method), and output it to the page.

In order to improve operational efficiency, a large number of JavaScript scripts are embedded in zhsoft.jsp, which is used to implement additions and delete operations. After clicking the "OK" button, then the Apply.jsp Batch update database is called.

2, apply.jsp This JSP file is used to accept the increase, delete parameters of the main page, update the database according to the contents, and then return to the main page after completion. Apply.jsp needs to get the parameters: 1 group_id: Current group ID 2 group_pageno: Group list box page number 3 Candidate_pageno: Candidate list box page number 4 Current_pageno: Current list box page number 5 Added: To increase the user ID list ( Commerity separation) 6 deleded: The user ID list to be deleted (separated by a comma) Apply.jsp lists the list of user IDs to be deleted, analyzing with the StringTokenizer class, and then call the DBCON class RunUpdate method to add the Database. Apply.jsp After completing the update operation, use an implicit form form formApply, the target of the form is zhsoft.jsp, so the form is submitted to the main page of the linkage paging list box. 3. Error.jsp This is the error page for this JSP file. When an exception occurs when JSP compiles, the web server throws this exception to this page. This page is very simple, but the exception information is displayed, so he will not be described here. Fourth, the Linked Paging List Box Test Linkage Paging List Box program is WebLogic 6.1, the database is Oracle8i. You need to configure the following before the test: 1. Configure the WebLogic 6.1 built-in connection pool OraclePool and the data source Oracleds. The procedure is as follows: 1 Log in to the main console page of WebLogic 6.1 (such as http: // localhost: 7001 / console) as the System user; 277777937767676767 The pool clicks the "Create" button Create an OraclePool connection pool. 3 Select the service MyServer for the OraclePool Connection Pool, so that myserver is started, the connection pool can be used, the setting screen is as follows: Figure 9, load the connection pool into the service After selecting the "Apply" button to take effect. 4 Create a data source ORACLEDS (JNDI name), which is mapped to the OraclePool connection pool, the setting screen is as follows: Figure 10, establish a data source to connect the data source to establish an ORACLEDS data source, then do not forget to click "Targets", at this time A screen similar to the 3rd 3 will appear, apply the data source to the MyServer service, press "Apply" to take effect. 2, copy procedure: Copy the JSP file of the linkage page list box (zhsoft.jsp, apply.jsp, and error.jsp) and the execution code of the JavaBean program (Class file) to the defaultWebApp directory of WebLogic 6.1, the button diagram Like files copied to the defaultwebapp / images directory.

转载请注明原文地址:https://www.9cbs.com/read-106204.html

New Post(0)