大家好,小弟刚学jsp+selevt 不多久 遇到问题也不知道怎么解决
各位看图片1 帮忙,谢谢了,
图2 实现效果再次感谢了。
各位看图片1 帮忙,谢谢了,
图2 实现效果再次感谢了。
解决方案 »
- ubuntu server 用tomcat6部署jsp工程的问题
- java模拟用户登录问题!高手大哥请留步小弟被这个问题缠很久了。快发疯了帮帮我!请看内容
- 启动Tomcat报错
- 求简单的struts,struts+hibernate,struts+hibernate+spring小例子
- BBs注册不能像SQL SERVER 数据库中插入数据 检索插入数据的表也检索不了 急?????????
- 救命吖,(JavaMail问题)javax.mail.internet.ParseException: Unbalanced quoted string
- 请各位帮帮忙,对你们来说是小问题,对我这个初学者来说是大问题,多谢了!
- jsp怎样将图片上传到SQLServer2005数据库保存
- 请教:JSP能否调用服务器端的exe程序?解决即结帐!
- jsp这嬷脆弱?
- json格式嵌套的怎么去值?
- 本人小白一直有个概念上的问题求解,关于上传
int pageNo = 1; //表示当前的页数
final int pageNumSize = 6;//表示最多一页显示多少条页码号
int totalPages = 10; //表示一共要显示多少页的数据,这是你通过数据库查询算出来的
int maxPageNo = (pageNo/pageNumSize+1)*pageNumSize;//表示当前页需要显示的页码号的最大数
for(int i=pageNo/pageNumSize*pageNumSize + 1;
i<=(maxPageNo > totalPages ? totalPages : maxPageNo);i++) {
System.out.println(i);
}
反正方法类似就这样。但用session来保存信息就不敢苟同了…
final int pageNumSize = 6;//表示最多一页显示多少条页码号
int pageNo = 4; //表示当前的页数
int totalPages = 10; //表示一共要显示多少页的数据
int startPageNo = pageNo/(pageNumSize + 1)*pageNumSize + 1;//开始页码数
int endPageNo = (pageNo + pageNumSize - 1)/pageNumSize*pageNumSize;//结束页码数
for(int i= startPageNo;
i<=(endPageNo > totalPages ? totalPages : endPageNo);i++) {
System.out.println(i);
}
final int pageNumSize = 6;//表示最多一页显示多少条页码号
int pageNo = 6; //表示当前的页数
int totalPages = 10; //表示一共要显示多少页的数据
int startPageNo = pageNo;//开始页码数
int endPageNo = pageNo + pageNumSize - 1;//结束页码数
for(int i= startPageNo;
i<=(endPageNo > totalPages ? totalPages : endPageNo);i++) {
System.out.println(i);
}
你好,你的方法确实很好,我把我前台效果图给你看下可是问题又出现了。那家 粗 的 2 是当前页面
点击过后 1页面 没有消失 后面的6 页面没有加载出来 ?
我是用 <c:forEach > 标签循环出来的,我写的前台代码有Bug?
<input type="hidden" id="totalPage" name="totalPage" value="${(totalPage)!}"/>
并在要显示的地方得到totalPagediv align="right">
<span id="news_page1">
<script type="text/javascript">
var pg = new showPages("pg");
var pageCounts = document.getElementById("totalPage").value;
pg.pageCount = pageCounts; //定义总页数(必要)
pg.argName = "page"; //定义参数名(可选,缺省为page)
pg.printHtml();
</script>
</span>
</div> 下面HTML和js复制下来可以直接运行<html>
<head>
<title>showPages.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="showPages.js"></script> <style type="text/css">
<!--
.listhome{ font-family:Arial, Helvetica, sans-serif; background:url(images/bgline.jpg) repeat-x; width:56px; height:22px; line-height:22px; border:#e3e3e3 1px solid; font-size:12px; color:#666666; display:inline-block; text-align:center;text-decoration:none; margin-left:6px;}
.listhome a{ text-decoration:none;}
.listhome a:hover{text-decoration:none;}
.list01{ font-family:Arial, Helvetica, sans-serif;width:26px; height:22px; line-height:22px; border:#e3e3e3 1px solid; font-size:12px; color:#666666; display:inline-block; text-align:center;text-decoration:none; margin-left:6px;}
.list01 a{ text-decoration:none;}
.list01 a:hover{text-decoration:none;}
.list02{ font-family:Arial, Helvetica, sans-serif;width:26px; height:22px; line-height:22px; background:#b40e1c; border:#b40e1c 1px solid; font-size:12px; color:#fff; display:inline-block; text-align:center;text-decoration:none; margin-left:6px;}
.list02 a{ text-decoration:none;}
.list02 a:hover{text-decoration:none;}
.list03{ font-family:Arial, Helvetica, sans-serif; height:22px; line-height:22px; font-size:12px; color:#666; margin-left:6px;}
-->
</style> </head>
<body>
<script type="text/javascript">
var pg = new showPages('pg');
pg.pageCount = 10; //定义总页数(必要)
pg.argName = 'page'; //定义参数名(可选,缺省为page)
pg.printHtml(); //显示页数
</script>
</body>
</html> js/*var pg = new showPages('pg');
pg.pageCount = 12; //定义总页数(必要)
pg.argName = 'p'; //定义参数名(可选,缺省为page)
pg.printHtml(); //显示页数
Supported in Internet Explorer, Mozilla Firefox
*/function showPages(name) { //初始化属性
this.name = name; //对象名称
this.page = 1; //当前页数
this.pageCount = 10; //总页数
this.argName = 'page'; //参数名
this.showTimes = 1; //打印次数
}showPages.prototype.getPage = function(){ //丛url获得当前页数,如果变量重复只获取最后一个
var args = location.search;
var reg = new RegExp('[\?&]?' + this.argName + '=([^&]*)[&$]?', 'gi');
var chk = args.match(reg);
this.page = RegExp.$1;
}
showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证
if (isNaN(parseInt(this.page))) this.page = 1;
if (isNaN(parseInt(this.pageCount))) this.pageCount = 1;
if (this.page < 1) this.page = 1;
if (this.pageCount < 1) this.pageCount = 1;
if (parseInt(this.page) > parseInt(this.pageCount)) this.page = this.pageCount;
this.page = parseInt(this.page);
this.pageCount = parseInt(this.pageCount);
}
showPages.prototype.createHtml = function(mode){ //生成html代码
var strHtml = '', prevPage = this.page - 1, nextPage = this.page + 1; //
strHtml += '<span class="list03">共' + this.pageCount + '页  当前第 <strong>' + this.page + '</strong> 页 </span>';
strHtml += '<span>';
if (prevPage < 1) {
strHtml += '<span title="First Page" class="listhome">首页</span> ';
strHtml += '<span title="Prev Page" class="listhome">上一页</span> ';
} else {
strHtml += '<span title="First Page"><a class="listhome" href="javascript:' + this.name + '.toPage(1);">首页</a></span> ';
strHtml += '<span title="Prev Page"><a class="listhome" href="javascript:' + this.name + '.toPage(' + prevPage + ');">上一页</a></span> ';
}
if (this.page != 1) strHtml += '<span title="Page 1" class="listhome" ><a href="javascript:' + this.name + '.toPage(1);">1</a></span>';
if (this.page >= 10) strHtml += '<span class="list01">...</span>';
if (this.pageCount > this.page + 2) {
var endPage = this.page + 2;
} else {
var endPage = this.pageCount;
}
for (var i = this.page - 2; i <= endPage; i++) {
if (i > 0) {
if (i == this.page) {
strHtml += '<span title="Page ' + i + '" class="list02">' + i + '</span>';
} else {
if (i != 1 && i != this.pageCount) {
strHtml += '<span title="Page ' + i + '" class="list01"><a href="javascript:' + this.name + '.toPage(' + i + ');">' + i + '</a></span>';
}
}
}
}
if (this.page + 3 < this.pageCount) strHtml += '<span class="list01">...</span>';
if (this.page != this.pageCount) strHtml += '<span title="Page ' + this.pageCount + '"><a class="listhome" href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">' + this.pageCount + '</a></span>';
if (nextPage > this.pageCount) {
strHtml += ' <span title="Next Page" class="listhome">下一页</span>';
strHtml += ' <span title="Last Page" class="listhome">尾页</span>';
} else {
strHtml += ' <span title="Next Page"><a class="listhome" href="javascript:' + this.name + '.toPage(' + nextPage + ');">下一页</a></span>';
strHtml += ' <span title="Last Page"><a class="listhome" href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">尾页</a></span>';
}
strHtml += '</span><br />'; return strHtml;
}
showPages.prototype.createUrl = function (page) { //生成页面跳转url
if (isNaN(parseInt(page))) page = 1;
if (page < 1) page = 1;
if (page > this.pageCount) page = this.pageCount;
var url = location.protocol + '//' + location.host + location.pathname;
var args = location.search;
var reg = new RegExp('([\?&]?)' + this.argName + '=[^&]*[&$]?', 'gi');
args = args.replace(reg,'$1');
if (args == '' || args == null) {
args += '?' + this.argName + '=' + page;
} else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
args += this.argName + '=' + page;
} else {
args += '&' + this.argName + '=' + page;
}
return url + args;
}
showPages.prototype.toPage = function(page){ //页面跳转
var turnTo = 1;
if (typeof(page) == 'object') {
turnTo = page.options[page.selectedIndex].value;
} else {
turnTo = page;
}
self.location.href = this.createUrl(turnTo);
}
showPages.prototype.printHtml = function(mode){ //显示html代码
this.getPage();
this.checkPages();
this.showTimes += 1;
document.write('<div id="pages_' + this.name + '_' + this.showTimes + '" class="page"></div>');
document.getElementById('pages_' + this.name + '_' + this.showTimes).innerHTML = this.createHtml(mode);
}
showPages.prototype.formatInputPage = function(e){ //限定输入页数格式
var ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
if(!ie) var key = e.which;
else var key = event.keyCode;
if (key == 8 || key == 46 || (key >= 48 && key <= 57)) return true;
return false;
}