´¿JSP·ÖÒ³´úÂë
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%
//Çý¶¯³ÌÐòÃû
String driverName="org.gjt.mm.mysql.Driver";
//Êý¾Ý¿âÓû§Ãû
String userName="root";
//ÃÜÂë
String userPasswd="<>?KL:IOP*()";
//Êý¾Ý¿âÃû
String dbName="gb_winguo_db";
//±íÃû
String tableName="keyword_type";
//Áª½á×Ö·û´®
String url="jdbc:mysql://127.0.0.1/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//ÿҳÏÔʾ¼Ç¼Êý
int PageSize = 20;
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" mce_href="style.css" type="text/css">
Ïà¹ØÎĵµ£º
ÏÂÔØºóµ¼ÈëÏîÄ¿µ½ MyEclipse , È»ºóÐÞ¸ÄÊý¾Ý¿âÁ¬½Ó²ÎÊý¼´¿É²âÊÔ. ÎÒÕâÓõÄÊÇ MySQL Êý¾Ý¿â. Óà JSP ÊÇÒòΪ Hibernate ¿ÉÒÔÅäºÏ¸÷ÖÖ¿ò¼Ü, Òò´ËÔÚ´úÂëÀïÎÒÒѾ¾¡Á¿µÄ°ÑÒ³ÃæºÍºǫ́µÄÖ±½Ó±äÁ¿ñîºÏ·Ö¸ô¿ªÁË.
hibernate_page.zip 433KB
²¿·Ö´úÂëÏÔʾ:
Ïà¹Ø SQL:
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`u ......
ʹÓÃCactus¶Ôtaglib½øÐе¥Ôª²âÊÔ ÏÂͼÃèÊöÁËʹÓÃCactus¶Ô±ê¼Ç¿âµÄÒ»¸ö±ê¼Ç½øÐе¥Ôª²âÊԵĹý³Ì¡£(ͼƬÁ´½Ó) 1.Cactus¶ÔÏó³õʼ»¯²âÊÔÀ࣬¸ÃÀà±ØÐëÅÉÉú×ÔJspTestCaseÀ࣬²âÊÔ±ê¼ÇʱËùÐèÒªµÄÈκÎHTTP²ÎÊý£¬¶¼ÐèÒªÔÚbeginXXX·½·¨ÖнøÐÐÅäÖá£ÀýÈ磬Èç¹ûij±ê¼Ç´ÓHttp²ÎÊýÌáÈ¡ÐÅÏ¢£¬ÄÇôÄãÐèÒªÔÚbeginXXX·½·¨Öж¨Òå¸Ã²ÎÊý¡£ ......
ÔÚÒ»¸öÏîÄ¿Öзּ¶Ñ¡ÔñÐÐÕþÇø»®Ê±Óõ½AJAX½øÐÐÎÞˢм¶Áª£¬ÎÒÔÚÒ³ÃæÖбàÂëÓõÄÊÇUTF-8£¬×ÜÊDZ¨½Å±¾´íÎó£¬
ÎÒ°ÑÒ³Ãæ±àÂë»»³ÉGBKÓÖÊÇÕý³£µÄ£¬ºóÀ´ÔÚÍøÉÏËÑË÷ÁËһϣ¬ÔÚÒýÈëJSʱ¼ÓÈë±àÂë¾Í¿ÉÒÔÁË£¬ÈçÏ£º
<script language="Javascript" src="js/jquery.js" charset="gb2312"></script> ......
¶¨ÒåÒ»¸ösession±äÁ¿
session.setAttribute("user_name","joan");
¶Áȡһ¸ösessionµÄÖµ:
String your_name=session.getAttribute("user_name");
ÅжÏÒ»¸ösessionÊÇ·ñ´æÔÚÓ¦ÓÃ:
if((String)session.getAttribute("user_id")==null)
{
out.print("yes");
}
else
{
out.print("no");
}
дÈëÒ»¸öcook ......
1£º³¬Á¬½ÓÌø×ª
ÎÒÃÇÔÚ³¬Á¬½ÓµÄʱºò£¬³£³£Á¬½Óµ½Ò»¸öjsp»òÕßAction,±ÈÈç:
XXX
ÕâÑù×ö»áÓÐÒ»¸öÎÊÌ⣺ÔÚtest.jspÖУ¬³ýÄã´«µÝµÄparam1ºÍparam2²ÎÊýÍâ,ÄãÓÃrequest.getParamter()È¡ÈκÎÔÀ´Ò³ÃæµÄ±íµ¥ÔªËض¼»áΪ¿Õ£¬ÕâÊÇÒòΪÕâÖÖ·½Ê½»á²úÉúеÄrequestÉúÃüÖÜÆÚ£¬ÔÚÕâ¸örequestÖÐÖ»»á°üº¬³¬Á¬½Óºó¸úËæµÄ?param1ÕâÖÖ²ÎÊý£¬ Òò´ ......