手机访问 | 设为首页 | 加入收藏 | 网站地图

当前位置:电脑中国 > 编程 > JSP >

jsp+jdbc+MySQL分页

2014-09-16 20:14|来源:本站搜集整理 |作者:电脑技巧 |点击:

MySQL自带的limit方式可以完成真分页。具体结构和代码如下:

\

 

index.jsp

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
 
 
  
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  
  
  
    <form action="<%=path %>/ShowPerson">
        <table>
            <tbody><tr>
            <!-- 隐藏域:通过getParameter方法传值currentPage -->
            <td><input type="hidden" name="currentPage" value="1"></td>
                <td>查看所有成员信息</td>
                <td><input type="submit" value="GO!"></td>
            </tr>
        </tbody></table>
    </form>
 

Person.java

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.ibm.pojo;
 
public class Person {
    /**
     * Person类属性:id,姓名,年龄
     */
    private int id;
    private String name;
    private int age;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}
(责任编辑:电脑技巧)
图片推荐
    友荐云推荐
网友评论