mysql控制台 分页显示_一个简单的分页(mysql) 简单实现

mybook.jsp

对于原始session.currentPage可以再jsp种实现 也可以在 事件消息 HttpSessionListener中实现

pageEncoding="UTF-8"%>

href="http://localhost/show/css/you.css" mce_href="http://localhost/show/css/you.css"

type="text/css"/>

Insert title here

you.js

$(document).ready(function(){

$("span.click").click(function(){

var xmlhttp;

if (window.XMLHttpRequest)

{// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

else

{// code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function()

{

if (xmlhttp.readyState==4 && xmlhttp.status==200)

{

location.reload();

}

};

xmlhttp.open("GET","./change?page="+$(this).html(),true);

xmlhttp.send();

});

});

我使用自定义标签实现的,

标签

package my;

import java.io.IOException;

import java.sql.*;

import javax.servlet.jsp.tagext.*;

public class Query extends SimpleTagSupport {

private Statement statement ;

private String table=null;

private int page,number=2;

private ResultSet resultSet;

private String follow="";

public void doTag(){

String querySql="SELECT name,price FROM "+table;

try {

statement =MySql.getStatement("why", "root", "root");

resultSet=statement.executeQuery(querySql);

this.getJspContext().getOut().println("
"+"
"+getResult());

} catch (Exception e){

// TODO Auto-generated catch block

e.printStackTrace();

}

}

private String getResult() throws Exception{

int totalRow,totalPage;

String str = null;

if(((page-1)==0||resultSet.absolute((page-1)*number))&&resultSet.last()){

totalRow=resultSet.getRow();

totalPage=totalRow/number+(totalRow%number==0?0:1);

if(page-1>0)

resultSet.absolute((page-1)*number);

else

resultSet.beforeFirst();

}else{

follow+="null";

return null;

}

for(int i=0;i

str+="

"+resultSet.getString("name")+"
"+resultSet.getDouble("price")+"

";

follow+=resultSet.getString("name")+resultSet.getDouble("price");

}

for(int i=1;i<=totalPage;++i){

if(i==page){

str+=""+i+"";

continue;

}

str+=""+i+"";

}

return str;

}

public void setTable(String table){

this.table=table;

}

public void setPage(int page){

this.page=page;

}

public void setNumber(int number){

this.number=number;

}

}

why.tld

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"

version="2.0">

1.0

why

to

my.Example

empty

here

query

my.Query

empty

table

true

page

true

true

number

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值