四月十日

今天完成了科技政策查询系统,学习了分页显示。

具体效果如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
    <%@ page import="java.sql.Connection"%> 
<%@ page import="java.sql.PreparedStatement"%> 
<%@ page import="java.sql.SQLException"%> 
<%@ page import="java.sql.Statement"%> 
<%@ page import="java.sql.ResultSet"%> 
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/layuimini/js/lay-module/echarts/echarts.js}"></script>
    <script th:src="@{/layuimini/js/lay-module/echarts/wordcloud.js}"></script>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <script src="https://www.layuicdn.com/layui/layui.js"></script>

</head>


<%
java.sql.Connection sqlCon; //数据库连接对象
java.sql.Statement sqlStmt; //SQL语句对象
java.sql.ResultSet sqlRst;  //结果集对象
java.lang.String strCon;    //数据库连接字符串
java.lang.String strSQL;    //SQL语句
int intPageSize;           //一页显示的记录数
int intRowCount;           //记录总数
int intPageCount;          //总页数
int intPage;               //待显示页码
java.lang.String strPage; 



String name = (String) session.getAttribute("name");

String id = (String) session.getAttribute("id");

String organ = (String) session.getAttribute("organ");

int i;
//设置一页显示的记录数
intPageSize = 10;

//取得待显示页码
strPage = request.getParameter("page");

if(strPage==null){
    //表明在QueryString中没有page这一个参数,此时显示第一页数据
    intPage = 1;
} else {
    //将字符串转换成整型
    intPage =java.lang.Integer.parseInt(strPage);
    if(intPage<1) intPage = 1;
}
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();  
String username = "root"; //用户名
String password = "NN06280055"; //密码
String url="jdbc:mysql://localhost:3306/ceshi?useUnicode=true&characterEncoding=UTF-8";
//连接数据库
sqlCon=java.sql.DriverManager.getConnection(url,username,password);
//创建语句对象
sqlStmt =sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//创建查询语句
    strSQL = "select * from policy where id like '%"+ id + "%' and name like '%"+ name +"%' and organ like '%" + organ +"%'";
//执行SQL语句并获取结果集
sqlRst = sqlStmt.executeQuery(strSQL);
//获取记录总数
sqlRst.last();
intRowCount = sqlRst.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) /intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
    
%>

<table class="layui-table"style="table-layout: fixed;word-wrap:break-word;" >
    <thead>
    <tr>
        <td style="width: 300px">政策名称</td>
        <td style="width: 150px">发文机构</td>
        <td style="width: 70px">颁布日期</td>
        <td style="width: 80px">政策分类</td>
    </tr>
    <% if(intPageCount>0) {

                   //将记录指针定位到待显示页的第一条记录上

                   sqlRst.absolute((intPage-1)* intPageSize + 1);

                   //显示数据

                   i = 0;

                   while(i<intPageSize &&!sqlRst.isAfterLast()){

            %>

                <tr>
            <td><%=(sqlRst.getString("name")) %></td>
            <td><%=(sqlRst.getString("organ")) %></td>
            <td><%=(sqlRst.getString("pubdata")) %></td>
            <td><%=(sqlRst.getString("type")) %></td>
            </tr>



            <% sqlRst.next();

               i++;

               }

               }

            %>
    </thead>
</table>
<center><%=intPage%>页 共<%=intPageCount%>页 共<%=intRowCount %><% //以下是分页的“上一页”“下一页”,有上一页就有链接,没有就为文字,下一页同理%>

        <% if(intPage>1){ %>

            <a href="table1.jsp?page=<%=intPage-1%>">上一页</a>

        <% }else{ %>

            上一页

        <%}%>



        <% if(intPage<intPageCount){ %>

            <a href="table1.jsp?page=<%=intPage+1%>">下一页</a>

        <% }else{ %>

            下一页

        <%}%>

     <center>
     <%

   //关闭结果集

   sqlRst.close();

   //关闭SQL语句对象

   sqlRst.close();

   //关闭数据库

   sqlRst.close();

%>



</html>
View Code

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/layuimini/js/lay-module/echarts/echarts.js}"></script>
    <script th:src="@{/layuimini/js/lay-module/echarts/wordcloud.js}"></script>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
</head>
<body>
<div  style="width:100%;height:85px;float:left; position:relative; display: table-cell;vertical-align: middle;">
 <div><img src="images/LOGO.png" height="50" width="50"></div>
<h1>河北省科技政策查询系统</h1>
</div>
<div  style="width:100%;height:65px;float:left; position:relative; display: table-cell;vertical-align: middle;  background-color: rgba(232,232,232,0.76) ">

    <form action="findallnew1.jsp" method="get" target="hideIframe1">
        <p> </p>
        <div class="layui-form-item">

            <div class="layui-inline">

                <label class="layui-form-label">
                    政策名称:
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="name"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">
                    政策文号:
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="id"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">
                    发文机构:
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="organ"  class="layui-input">
                </div>
                
            </div>
            <div class="layui-inline">
                            <label class="layui-form-label">
                    全局搜索:
                </label>
                <div class="layui-input-inline">
                    <input type="text" name=""  class="layui-input">
                </div>
                
            </div>
            <div class="layui-inline">
                <div class="layui-form-label">
                    <center><button type="submit" class="layui-btn" lay-submit  lay-filter="demo1" style="background-color: #1571b2">查询</button></center>
                </div>
            </div>
        </div>
    </form>
</div>
</br>
</br>
</br>
</br>
</br>
<div class="container3">
    <iframe id="myIframe1" name="hideIframe1" style="" src="table1.jsp" frameborder="0" width="100%" height="850px"></iframe>
</div>

</body>
</html>
View Code
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1 style="text-align: center;"></h1>
<br>
<%
String name = request.getParameter("name");
session.setAttribute("name",name);
String id = request.getParameter("id");
session.setAttribute("id",id);
String organ = request.getParameter("organ");
session.setAttribute("organ",organ);
%>
<jsp:forward page ="table1.jsp"/>
</body>
</html>

 

posted @ 2023-04-10 21:40  布吉岛???  阅读(60)  评论(0编辑  收藏  举报