Ä¿Ç°×îºÃµÄJSP·ÖÒ³¼¼Êõ
Ç°ÑÔ
ÔÚʹÓÃÊý¾Ý¿âµÄ¹ý³ÌÖУ¬²»¿É±ÜÃâµÄÐèҪʹÓõ½·ÖÒ³µÄ¹¦ÄÜ£¬¿ÉÊÇJDBCµÄ¹æ·¶¶Ô´ËȴûÓкܺõĽâ¾ö¡£¶ÔÓÚÕâ¸öÐèÇóºÜ¶àÅóÓѶ¼ÓÐ×Ô¼ºµÄ½â¾ö·½°¸£¬±ÈÈçʹÓÃVectorµÈ¼¯ºÏÀàÏȱ£´æÈ¡³öµÄÊý¾ÝÔÙ·ÖÒ³¡£µ«ÕâÖÖ·½·¨µÄ¿ÉÓÃÐԺܲÓëJDBC±¾ÉíµÄ½Ó¿ÚÍêÈ«²»Í¬£¬¶Ô²»Í¬ÀàÐ͵Ä×ֶεÄÖ§³ÖÒ²²»ºÃ¡£ÕâÀïÌṩÁËÒ»ÖÖÓëJDBC¼æÈÝÐԷdz£ºÃµÄ·½°¸¡£
JDBCºÍ·ÖÒ³
SunµÄJDBC¹æ·¶µÄÖƶ¨£¬ÓÐʱºÜÈÃÈË¿ÞЦ²»µÃ£¬ÔÚJDBC1.0ÖУ¬¶ÔÓÚÒ»¸ö½á¹û¼¯£¨ResultSet£©ÄãÉõÖÁÖ»ÄÜÖ´ÐÐnext()²Ù×÷£¬¶øÎÞ·¨ÈÃÆäÏòºó¹ö¶¯£¬Õâ¾ÍÖ±½Óµ¼ÖÂÔÚÖ»Ö´ÐÐÒ»´ÎSQL²éѯµÄÇé¿öÏÂÎÞ·¨»ñµÃ½á¹û¼¯µÄ´óС¡£ËùÒÔ£¬Èç¹ûÄãʹÓõÄÊÇJDBC1.0µÄÇý¶¯£¬ÄÇôÊǼ¸ºõÎÞ·¨ÊµÏÖ·ÖÒ³µÄ¡£
ºÃÔÚSunµÄJDBC2¹æ·¶ÖкܺõÄÃÖ²¹ÁËÕâÒ»¸ö²»×㣬Ôö¼ÓÁ˽á¹û¼¯µÄÇ°ºó¹ö¶¯²Ù×÷£¬ËäÈ»ÈÔÈ»²»ÄÜÖ±½ÓÖ§³Ö·ÖÒ³£¬µ«ÎÒÃÇÒѾ¿ÉÒÔÔÚÕâ¸ö»ù´¡ÉÏд³ö×Ô¼ºµÄ¿ÉÖ§³Ö·ÖÒ³µÄResultSetÁË¡£
ºÍ¾ßÌåÊý¾Ý¿âÏà¹ØµÄʵÏÖ·½·¨
ÓÐһЩÊý¾Ý¿â£¬ÈçMysql, OracleµÈÓÐ×Ô¼ºµÄ·ÖÒ³·½·¨£¬±ÈÈçMysql¿ÉÒÔʹÓÃlimit×Ӿ䣬Oracle¿ÉÒÔʹÓÃROWNUMÀ´ÏÞÖƽá¹û¼¯µÄ´óСºÍÆðʼλÖá£ÕâÀïÒÔMysqlΪÀý£¬ÆäµäÐÍ´úÂëÈçÏ£º
1.// ¼ÆËã×ܵļǼÌõÊý
2.String SQL = "SELECT Count(*) AS total " + this.QueryPart;
3.rs = db.executeQuery(SQL);
4.if (rs.next())
5.Total = rs.getInt(1);
6.// ÉèÖõ±Ç°Ò³ÊýºÍ×ÜÒ³Êý
7.TPages = (int)Math.ceil((double)this.Total/this.MaxLine);
8.CPages = (int)Math.floor((double)Offset/this.MaxLine+1);
9.// ¸ù¾ÝÌõ¼þÅжϣ¬È¡³öËùÐè¼Ç¼
10.if (Total > 0) {
11.SQL = Query + " LIMIT " + Offset + " , " + MaxLine;
12.rs = db.executeQuery(SQL);
13.}
14.return rs;
15.}
¸´ÖÆ´úÂë
ºÁÎÞÒÉÎÊ£¬Õâ¶Î´úÂëÔÚÊý¾Ý¿âÊÇMysqlʱ½«»áÊÇƯÁÁµÄ£¬µ«ÊÇ×÷Ϊһ¸öͨÓõÄÀࣨÊÂʵÉÏÎÒºóÃæÒªÌṩµÄ¾ÍÊÇÒ»¸öͨÓÃÀà¿âÖеÄÒ»²¿·Ö£©£¬ÐèÒªÊÊÓ¦²»Í¬µÄÊý¾Ý¿â£¬¶ø»ùÓÚÕâ¸öÀࣨ¿â£©µÄÓ¦Óã¬Ò²¿ÉÄÜʹÓò»Í¬µÄÊý¾Ý¿â£¬ËùÒÔ£¬ÎÒÃǽ«²»Ê¹ÓÃÕâÖÖ·½·¨¡£
ÁíÒ»ÖÖ·±ËöµÄʵÏÖ·½·¨
ÎÒ¿´¹ýһЩÈ˵Ä×ö·¨£¨ÊÂʵÉÏ°üÀ¨ÎÒÔÚÄÚ£¬Ò»¿ªÊ¼Ò²ÊÇʹÓÃÕâÖÖ·½·¨µÄ£©£¬¼´²»Ê¹ÓÃÈκηâ×°£¬ÔÚÐèÒª·ÖÒ³µÄµØ·½£¬Ö±½Ó²Ù×÷ResultSet¹öµ½ÏàÓ¦µÄλÖã¬ÔÙ¶ÁÈ¡ÏàÓ¦ÊýÁ¿µÄ¼Ç¼¡£ÆäµäÐÍ´úÂëÈçÏ£º
1.<%
2.sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
3.java.sql.ResultSet.CONCUR_READ_ONLY);
4.strSQL = "select name,age from
Ïà¹ØÎĵµ£º
Cookie¶ÔÏóÊÇÓÉWeb·þÎñÆ÷²úÉúºó±£´æÔÚä¯ÀÀÆ÷ÖеÄÐÅÏ¢£¬Ëü¿ÉÒÔÓÃÀ´±£´æһЩСÁ¿µÄÐÅÏ¢ÔÚä¯ÀÀÆ÷ÖУ»¸Ã¶ÔÏó²»ÊôÓÚJspµÄÄÚÖöÔÏó£¬ËüÐèÒª¹¹Ôì²ÅÄÜʹÓÃ
1. ¹¹Ô죺
Cookie cookie¶ÔÏóÃû=new Cookie(cookie±äÁ¿Ãû£¬cookieÖÐËù´æ´¢µÄ¶ÔÏó)
2. cookieµÄдÈëÓë¶ÁÈ¡
&nbs ......
pageEncoding£ºÉèÖÃJSPÔ´ÎļþºÍÏìÓ¦ÕýÎÄÖеÄ×Ö·û¼¯±àÂë¡£
contentType£ºÉèÖÃJSPÔ´ÎļþºÍÏìÓ¦ÕýÎĵÄ×Ö·û¼¯±àÂë¼°MIMEÀàÐÍ¡£
¿É¼û,pageEncodingºÍcontentType¶¼¿ÉÒÔÉèÖÃJSPÔ´ÎļþºÍÏìÓ¦ÕýÎÄÖеÄ×Ö·û¼¯±àÂë¡£µ«Ò²ÓÐÇø±ð:
ÉèÖÃJSPÔ´Îļþ×Ö·û¼¯Ê±,ÓÅÏȼ¶ÎªpageEncoding>contentType¡£Èç¹û¶¼Ã»ÓÐÉèÖã¬Ä¬ÈÏISO-8859-1¡£
......
¿ª·¢Ó¦ÓóÌÐò¹ý³ÌÖеÄģʽ¸ÅÄGOFÊÇÃæÏò¶ÔÏóÈí¼þģʽµÄȨÍþ£¬Ëü½«ÃæÏò¶ÔÏóµÄÉè¼Æģʽ·ÖΪÈýÖÖ»ù±¾ÀàÐÍ£º´´½¨Ä£Ê½£¬½á¹¹Ä£Ê½ºÍÐÐΪģʽ¡£
²ÉÓÃJSP¿ª·¢ÍøÕ¾µÄÈýÖÖģʽ£º
1.Ö±½ÓʹÓÃJSP
¿ª·¢Ð¡ÐÍÍøÕ¾£¬ÔÚJSPÒ³ÃæÖлìºÏHTMLºÍJava´úÂ룬ʹӦÓóÌÐòÄÑÒÔά»¤ºÍÀ©Õ¹;
2.ʹÓÃJSP+JavaBean
ÔÚҳà ......
package com.gc.tool;
import java.util.ArrayList;
import java.util.List;
public class MyPagination {
private int recordCount = 0;
private int pagesize = 0;
private int maxPage = 0;
&n ......
½ñÌì×ÜËã°Ñ
response.setHeader("progma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires" ......