JSP分页怎么实现
如题,希望高手能提供给我一个带注释的JSP+Servlet+javabean的全套程序,我是刚学JAVA的。谢谢了~...
如题,希望高手能提供给我一个带注释的JSP+Servlet+javabean的全套程序,我是刚学JAVA的。谢谢了~
展开
3个回答
展开全部
给你一个JS的分页.
不过,这样分页和数据库是异步的.
页面文件:
-----------------------------------------------------------------------------------------------
<HTML>
<BODY onload="loadpage()">
<div id=show_data></div>
<script language=javascript src="pageshow1.js"></script>
</BODY>
</HTML>
JS文件pageshow1.js
----------------------------------------------------------------------------------------------------
var data_p=new Array();
var dt_i=0;
var cul_name=0;
var cul_url=1;
var cul_title=2;
data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/2007/1121/1442591305.shtml';
data_p[dt_i][cul_title]='a1';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1121/1424591262.shtml';
data_p[dt_i][cul_title]='a2';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/2007/1121/1039591020.shtml';
data_p[dt_i][cul_title]='a3';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a4';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a5';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a6';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a7';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/x/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a8';
var index=1;
var counts=dt_i+1;
var totlepage=(counts%5==0)?(counts/5):(Math.ceil(counts/5));
var cpage=5;
function loadpage(){
loadcontrol(index);
}
function loadcontrol(con){
if(con==1){
index=1;
}else if(con==4){
index=totlepage;
}else if(con==2){
index=index>1?(index-1):1;
}else if(con==3){
index=index>=totlepage?totlepage:(index+1)
}
pageshou(index);
}
function pageshou(index){
var outstr="";
outstr+="<table border='1' width='100' align='center'>";
outstr+="<tr>";
outstr+="<td align='center'>";
outstr+="名";
outstr+="</td>";
outstr+="</tr>";
for(var i=(index-1)*cpage;i<((index*cpage)>counts?counts:(index*cpage));i++)
{
outstr+="<tr>";
outstr+="<td align='center'>";
outstr+="<a href='";
outstr+=data_p[i][cul_url]+"' >";
outstr+=data_p[i][cul_title];
outstr+="</a>";
outstr+="</td>";
outstr+="</tr>";
}
outstr+="<tr>";
outstr+="<td align='center'>";
if(index==1){
outstr+="<input type='button' name='first' onClick='loadcontrol(1)' value='FIRST' disabled>";
}else{
outstr+="<input type='button' name='first' onClick='loadcontrol(1)' value='FIRST'>";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==1){
outstr+="<input type='button' name='pre' onClick='loadcontrol(2)' value='PRE' disabled>";
}else{
outstr+="<input type='button' name='pre' onClick='loadcontrol(2)' value='PRE' >";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==totlepage){
outstr+="<input type='button' name='next' onClick='loadcontrol(3)' value='NEXT' disabled>";
}else{
outstr+="<input type='button' name='next' onClick='loadcontrol(3)' value='NEXT'>";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==totlepage){
outstr+="<input type='button' name='last' onClick='loadcontrol(4)' value='LAST' disabled>";
}else{
outstr+="<input type='button' name='last' onClick='loadcontrol(4)' value='LAST'>";
}
outstr+="</td>";
outstr+="</tr>";
outstr+="</table>";
document.getElementById("show_data").innerHTML=outstr;
return false;
}
不过,这样分页和数据库是异步的.
页面文件:
-----------------------------------------------------------------------------------------------
<HTML>
<BODY onload="loadpage()">
<div id=show_data></div>
<script language=javascript src="pageshow1.js"></script>
</BODY>
</HTML>
JS文件pageshow1.js
----------------------------------------------------------------------------------------------------
var data_p=new Array();
var dt_i=0;
var cul_name=0;
var cul_url=1;
var cul_title=2;
data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/2007/1121/1442591305.shtml';
data_p[dt_i][cul_title]='a1';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1121/1424591262.shtml';
data_p[dt_i][cul_title]='a2';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/2007/1121/1039591020.shtml';
data_p[dt_i][cul_title]='a3';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a4';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a5';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a6';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a7';
dt_i++;data_p[dt_i]=new Array();
data_p[dt_i][cul_name]='';
data_p[dt_i][cul_url]='http://123/x/p/2007/1120/1423590267.shtml';
data_p[dt_i][cul_title]='a8';
var index=1;
var counts=dt_i+1;
var totlepage=(counts%5==0)?(counts/5):(Math.ceil(counts/5));
var cpage=5;
function loadpage(){
loadcontrol(index);
}
function loadcontrol(con){
if(con==1){
index=1;
}else if(con==4){
index=totlepage;
}else if(con==2){
index=index>1?(index-1):1;
}else if(con==3){
index=index>=totlepage?totlepage:(index+1)
}
pageshou(index);
}
function pageshou(index){
var outstr="";
outstr+="<table border='1' width='100' align='center'>";
outstr+="<tr>";
outstr+="<td align='center'>";
outstr+="名";
outstr+="</td>";
outstr+="</tr>";
for(var i=(index-1)*cpage;i<((index*cpage)>counts?counts:(index*cpage));i++)
{
outstr+="<tr>";
outstr+="<td align='center'>";
outstr+="<a href='";
outstr+=data_p[i][cul_url]+"' >";
outstr+=data_p[i][cul_title];
outstr+="</a>";
outstr+="</td>";
outstr+="</tr>";
}
outstr+="<tr>";
outstr+="<td align='center'>";
if(index==1){
outstr+="<input type='button' name='first' onClick='loadcontrol(1)' value='FIRST' disabled>";
}else{
outstr+="<input type='button' name='first' onClick='loadcontrol(1)' value='FIRST'>";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==1){
outstr+="<input type='button' name='pre' onClick='loadcontrol(2)' value='PRE' disabled>";
}else{
outstr+="<input type='button' name='pre' onClick='loadcontrol(2)' value='PRE' >";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==totlepage){
outstr+="<input type='button' name='next' onClick='loadcontrol(3)' value='NEXT' disabled>";
}else{
outstr+="<input type='button' name='next' onClick='loadcontrol(3)' value='NEXT'>";
}
outstr+="</td>";
outstr+="<td align='center'>";
if(index==totlepage){
outstr+="<input type='button' name='last' onClick='loadcontrol(4)' value='LAST' disabled>";
}else{
outstr+="<input type='button' name='last' onClick='loadcontrol(4)' value='LAST'>";
}
outstr+="</td>";
outstr+="</tr>";
outstr+="</table>";
document.getElementById("show_data").innerHTML=outstr;
return false;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询