先上效果图
数据库脚本:
DROP DATABASE csdpsystem;
CREATE DATABASE csdpsystem
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
USE csdpsystem;
CREATE TABLE csdpsystem.student
(
studentID VARCHAR(8) NOT NULL,
studentName VARCHAR(12),
studentPassword VARCHAR(32),
sStatus INT ,
sIdentity VARCHAR(6) DEFAULT '学生',
sLastTime DATETIME,
CONSTRAINT pk_studentID PRIMARY KEY (studentID),
);
COMMIT ;
一共三个页面:使用技术是JSP+JDBC
page.jsp主页面
<%@ page import="java.sql.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
request.setCharacterEncoding("UTF-8");
%>
<html>
<head>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<meta http-equiv="Content-Type" content="text/html; charset='utf-8'" />
<base href="<%=basePath%>">
<title>学生查询</title>
</head>
<body>
<%!//设置连接数据库的参数
private static final String DBDRIVER = "com.mysql.jdbc.Driver";
private static final String DBURL = "jdbc:mysql://localhost:3306/csdpsystem";
private static final String DBUSER = "root";
private static final String DBPASSWORD = "";
%>
<%
String url = "/jsp/cdsp_information/manager/page.jsp";
int currentPage = 1;
String keyWord = "";//默认的关键字
int lineSize = 5;//每页显示的数据数
int allRecorders = 0;//保存总记录数
String column = "studentID";//定义默认的查询列
String columnData = "用户用户名:studentID|用户姓名:studentName|用户状态:sStatus";//可操作的查询列
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
%>
<%
try{//如果没有输入参数那么就会是null,null无法变为数字
currentPage = Integer.parseInt(request.getParameter("cp"));
}catch(Exception e){}
try{//如果没有输入参数那么就会是null,null无法变为数字
lineSize = Integer.parseInt(request.getParameter("ls"));
}catch(Exception e){}
if(request.getParameter("kw")!=null){//表示有查询的关键字
System.out.println("取得关键字:"+new String(