´¿JSP·ÖÒ³´úÂëÖ®Mysql
//ÔËÐÐͼ:
//Á¬½Ó×Ö·û´®
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//ÿҳÏÔʾ¼Ç¼Êý
int PageSize = 8;
int StartRow = 0; //¿ªÊ¼ÏÔʾ¼Ç¼µÄ±àºÅ
int PageNo=0;//ÐèÒªÏÔʾµÄÒ³Êý
int CounterStart=0;//ÿҳҳÂëµÄ³õʼֵ
int CounterEnd=0;//ÏÔʾҳÂëµÄ×î´óÖµ
int RecordCount=0;//×ܼǼÊý;
int MaxPage=0;//×ÜÒ³Êý
int PrevStart=0;//Ç°Ò»Ò³
int NextPage=0;//ÏÂÒ»Ò³
int LastRec=0;
int LastStartRecord=0;//×îºóÒ»Ò³¿ªÊ¼ÏÔʾ¼Ç¼µÄ±àºÅ
//»ñÈ¡ÐèÒªÏÔʾµÄÒ³Êý£¬ÓÉÓû§Ìá½»
if(request.getParameter("PageNo")==null){ //Èç¹ûΪ¿Õ£¬Ôò±íʾµÚ1Ò³
if(StartRow == 0){
PageNo = StartRow + 1; //É趨Ϊ1
}
}else{
PageNo = Integer.parseInt(request.getParameter("PageNo")); //»ñµÃÓû§Ìá½»µÄÒ³Êý
StartRow = (PageNo - 1) * PageSize; //»ñµÃ¿ªÊ¼ÏÔʾµÄ¼Ç¼±àºÅ
}
//ÒòΪÏÔʾҳÂëµÄÊýÁ¿ÊǶ¯Ì¬±ä»¯µÄ£¬¼ÙÈç×ܹ²ÓÐÒ»°ÙÒ³£¬Ôò²»¿ÉÄÜͬʱÏÔʾ100¸öÁ´½Ó¡£¶øÊǸù¾Ýµ±Ç°µÄÒ³ÊýÏÔʾ
//Ò»¶¨ÊýÁ¿µÄÒ³ÃæÁ´½Ó
//ÉèÖÃÏÔʾҳÂëµÄ³õʼֵ!!
if(PageNo % PageSize == 0){
CounterStart = PageNo - (PageSize - 1);
}else{
CounterStart = PageNo - (PageNo % PageSize) + 1;
}
CounterEnd = CounterStart + (PageSize - 1);
%>
<html>
<head>
<title>·ÖÒ³ÏÔʾ¼Ç¼</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<%
//»ñÈ¡×ܼǼÊý
ResultSet rs = statement.executeQuery("select count(*) from items" );
rs.next();
RecordCount = rs.getInt(1);
rs = statement.executeQuery("SELECT image_url,author,price,item_id from items ORDER BY item_id DESC LIMIT "
+StartRow+", "+PageSize);
//»ñÈ¡×ÜÒ³Êý
MaxPage = RecordCount % PageSize;
if(RecordCount % PageSize == 0){
MaxPage = RecordCoun
Ïà¹ØÎĵµ£º
http://www.egzcn.com/article/webbc/JSP/2006-03-22/2003.html À´Ô´
ÕªÒª£ºËäÈ»session»úÖÆÔÚwebÓ¦ÓóÌÐòÖб»²ÉÓÃÒѾºÜ³¤Ê±¼äÁË£¬µ«ÊÇÈÔÈ»ÓкܶàÈ˲»Çå³þsession»úÖƵı¾ÖÊ£¬ÒÔÖÁ²»ÄÜÕýÈ·µÄÓ¦ÓÃÕâÒ»¼¼Êõ¡£±¾ÎĽ«ÏêϸÌÖÂÛsessionµÄ¹¤×÷»úÖƲ¢ÇÒ¶ÔÔÚJava web applicationÖÐÓ¦ÓÃsession»úÖÆʱ³£¼ûµÄÎÊÌâ×÷ ......
1.RequestDispatcher.forward()
ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚb.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ.
µ«forward()ÎÞ·¨Öض ......
Ò»£ºweb.xmlÅäÖÃ
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>cont ......
JSP£¨java server page£©
JSPÊÇ·þÎñÆ÷¶ËÔËÐеÄÒ³Ã棬JSP±¾Ê¾ÍÊÇÒ»¸öÎĵµ£¬Ëû²»½ö¿ÉÒÔ°üº¬¾²Ì¬µÄHTML´úÂ룬Ҳ¿ÉÒÔ°üº¬¶¯Ì¬µÄJAVA´úÂ룬·þÎñÆ÷ÈÝÆ÷¿ÉÒÔ½«JSPת»»³ÉServlet·¢²¼£¬²¢½ÓÊÜÇëÇó¡£
JspÎļþÖ»Ðè·ÅÔÚÓ¦ÓÃÎļþϾͿÉÒÔÁË¡£
JSPÀý×Ó£º
<html>
<head& ......