5.23
政务查询系统网页
• 所花时间:1
• 代码行数:432
• 博客容量:1
• 代码如下:
<%--
Created by IntelliJ IDEA.
User: allofitisst
Date: 2024/4/30
Time: 15:26
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script>
function searchPolicies() {
var policyName = document.getElementById("policyName").value;
var documentNumber = document.getElementById("documentNumber").value;
var publishingOrgan = document.getElementById("publishingOrgan").value;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var policies = JSON.parse(xhr.responseText);
updatePolicyTable(policies);
}
};
xhr.open("GET", "searchPolicies?policyName=" + policyName + "&documentNumber=" + documentNumber + "&publishingOrgan=" + publishingOrgan, true);
xhr.send();
}
function updatePolicyTable(policies) {
var tableBody = document.getElementById("policyTableBody");
tableBody.innerHTML = "";
for (var i = 0; i < policies.length; i++) {
var policy = policies[i];
var newRow = tableBody.insertRow(i);
var nameCell = newRow.insertCell(0);
nameCell.textContent = policy.name;
var organCell = newRow.insertCell(1);
organCell.textContent = policy.organ;
var pubdateCell = newRow.insertCell(2);
pubdateCell.textContent = policy.pubdata;
var categoryCell = newRow.insertCell(3);
categoryCell.textContent = policy.category;
var actionCell = newRow.insertCell(4);
var viewLink = document.createElement("a");
viewLink.textContent = "查看";
viewLink.href = "#"; // 添加查看详情的链接
actionCell.appendChild(viewLink);
}
}
</script>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>科技政策查询系统</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #f1f1f1;
color: #fff;
padding: 10px 20px;
text-align: center;
}
.container {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background-color: #f5f5f5;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.search-section {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.search-section input[type="text"] {
flex: 1;
padding: 10px;
margin-right: 10px;
}
.search-section button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.results-section {
margin-top: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #007bff;
color: #fff;
}
.pagination {
margin-top: 20px;
text-align: center;
}
.footer {
background-color: #000;
color: #fff;
padding: 10px 20px;
text-align: center;
}
h1{
color: black;
}
</style>
</head>
<body>
<header>
<img src="LOGO.png" alt="LOGO" style="height: 40px; vertical-align: middle; margin-right: 10px;">
<h1>科技政策查询系统</h1>
</header>
<%@ page import="java.util.List" %>
<%@ page import="utils.Policy" %>
<%@ page import="utils.PolicyDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
// 获取当前页数,默认为第一页
int currentPage = (request.getParameter("page") != null) ? Integer.parseInt(request.getParameter("page")) : 1;
// 每页显示的记录数
int pageSize = 10;
// 获取当前页的数据
List<Policy> policies = PolicyDAO.queryByPage(currentPage, pageSize);
// 获取总记录数
int totalCount = PolicyDAO.queryAll().size();
// 计算总页数
int totalPages = (totalCount % pageSize == 0) ? (totalCount / pageSize) : (totalCount / pageSize + 1);
%>
<div class="container">
<section class="search-section">
<form class="" action="search.jsp">
<p> </p>
<div class="layui-form-item" style="display: flex; align-items: center;">
<div class="layui-inline" style="flex: 1;">
<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" style="flex: 1;">
<label class="layui-form-label">
政策文号:
</label>
<div class="layui-input-inline">
<input type="text" name="document" class="layui-input">
</div>
</div>
<div class="layui-inline" style="flex: 1;">
<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" style="flex: 1;">
<label class="layui-form-label">
内容查询:
</label>
<div class="layui-input-inline">
<input type="text" name="content" class="layui-input">
</div>
</div>
<div class="layui-inline" style="flex: 1;">
<div class="layui-input-inline">
<button type="submit" class="layui-btn" lay-submit lay-filter="demo1" style="background-color: #1571b2">查询</button>
</div>
</div>
</div>
</form>
</section>
<section class="results-section">
<table>
<thead>
<tr>
<th>政策名称</th>
<th>发文机构</th>
<th>颁布日期</th>
<th>政策分类</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<% for (Policy policy : policies) { %>
<tr>
<td><%= policy.name %></td>
<td><%= policy.organ %></td>
<td><%= policy.pubdata %></td>
<td><%= policy.category %></td>
<td><a href="policyDetails.jsp?policyId=<%= policy.id %>">查看</a></td>
</tr>
<% } %>
</tbody>
</table>
<div class="pagination">
<%-- 上一页按钮 --%>
<% if (currentPage > 1) { %>
<a href="?page=<%= currentPage - 1 %>">上一页</a>
<% } else { %>
<span>上一页</span>
<% } %>
<%-- 页码 --%>
<%
// 定义变量用于控制显示的页码数量
int numPageLinksToShow = 5;
int halfNumPageLinksToShow = numPageLinksToShow / 2;
int startPage = Math.max(1, currentPage - halfNumPageLinksToShow);
int endPage = Math.min(totalPages, startPage + numPageLinksToShow - 1);
int numEllipses = Math.max(0, currentPage - halfNumPageLinksToShow - 2) + Math.max(0, totalPages - (startPage + numPageLinksToShow - 1));
// 显示省略号
if (startPage > 1) { %>
<span>...</span>
<% }
for (int i = startPage; i <= endPage; i++) {
if (currentPage == i) { %>
<span><%= i %></span>
<% } else { %>
<a href="?page=<%= i %>"><%= i %></a>
<% }
}
// 显示省略号
if (endPage < totalPages) { %>
<span>...</span>
<% } %>
<%
if (currentPage < totalPages) { %>
<a href="?page=<%= totalPages %>"><%= totalPages %></a>
<% }
%>
<%-- 下一页按钮 --%>
<% if (currentPage < totalPages) { %>
<a href="?page=<%= currentPage + 1 %>">下一页</a>
<% } else { %>
<span>下一页</span>
<% } %>
</div>
</section>
</div>
<footer class="footer">
<p>Copyright 1996-2022 All Rights Reserved 版权所有:河北省科学技术情报研究院 河北省科技创新战略研究院 技术支持:河北省科技信息处理实验室</p>
</footer>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: allofitisst
Date: 2024/4/30
Time: 17:49
To change this template use File | Settings | File Templates.
--%>
<%@ page import="utils.PolicyDAO" %>
<%@ page import="utils.Policy" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
int policyId = Integer.parseInt(request.getParameter("policyId"));
Policy policy = PolicyDAO.getPolicyById(policyId);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>政策详情</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #007bff;
margin-bottom: 20px;
}
p {
font-size: 16px;
line-height: 1.6;
margin-bottom: 10px;
}
.policy-detail {
padding-left: 20px;
border-left: 4px solid #007bff;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>政策详情</h1>
<div class="policy-detail">
<p><strong>政策名称:</strong> <%= policy.name %></p>
<p><strong>发文机构:</strong> <%= policy.organ %></p>
<p><strong>颁布日期:</strong> <%= policy.pubdata %></p>
<p><strong>政策分类:</strong> <%= policy.category %></p>
<p><strong>政策内容:</strong></p>
<div><%= policy.text %></div>
</div>
</div>
</body>
</html>
<%@ page language= "java" contentType= "text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ page import="java.sql.*"%>
<%@ page import="java.util.List" %>
<%@ page import="utils.Policy" %>
<title>科技政策查询系统</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #f1f1f1;
color: #fff;
padding: 10px 20px;
text-align: center;
}
.container {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background-color: #f5f5f5;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.search-section {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.search-section input[type="text"] {
flex: 1;
padding: 10px;
margin-right: 10px;
}
.search-section button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.results-section {
margin-top: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #007bff;
color: #fff;
}
.pagination {
margin-top: 20px;
text-align: center;
}
.footer {
background-color: #000;
color: #fff;
padding: 10px 20px;
text-align: center;
}
h1{
color: black;
}
</style>
</head>
<body>
<header>
<img src="LOGO.png" alt="LOGO" style="height: 40px; vertical-align: middle; margin-right: 10px;">
<h1>科技政策查询系统</h1>
</header>
<div class="container">
<section class="search-section">
<form class="" action="search.jsp">
<p> </p>
<div class="layui-form-item" style="display: flex; align-items: center;">
<div class="layui-inline" style="flex: 1;">
<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" style="flex: 1;">
<label class="layui-form-label">
政策文号:
</label>
<div class="layui-input-inline">
<input type="text" name="document" class="layui-input">
</div>
</div>
<div class="layui-inline" style="flex: 1;">
<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" style="flex: 1;">
<label class="layui-form-label">
内容查询(高级检索支持使用运算符*、+、-、''、""、()):
</label>
<div class="layui-input-inline">
<input type="text" name="content" class="layui-input" maxlength="120">
</div>
</div>
<div class="layui-inline" style="flex: 1;">
<div class="layui-input-inline">
<button type="submit" class="layui-btn" lay-submit lay-filter="demo1" style="background-color: #1571b2">查询</button>
</div>
</div>
</div>
</form>
</section>
<section class="results-section">
<table>
<thead>
<tr>
<th>政策名称</th>
<th>发文机构</th>
<th>颁布日期</th>
<th>政策分类</th>
<th>操作</th>
</tr>
</thead>
<%
int count=0;
String a=request.getParameter("name");
String b=request.getParameter("document");
String c=request.getParameter("organ");
String d=request.getParameter("content");
String URL = "jdbc:mysql://localhost:3306/party";
String USERNAME = "root";
String PWD = "1234";
PreparedStatement pstmt = null;
ResultSet rs=null;
Connection connection = null;
List<Policy> ls;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(URL, USERNAME, PWD);
String sql ="SELECT * FROM policy WHERE name LIKE ? AND document LIKE ? AND organ LIKE ? AND text REGEXP ? ORDER BY id DESC " ;
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, "%"+a+"%");
pstmt.setString(2, "%"+b+"%");
pstmt.setString(3, "%"+c+"%");
pstmt.setString(4, convertToRegex(d));
rs= pstmt.executeQuery();
while(rs.next()) {
count++;
String name=rs.getString("name");
String organ=rs.getString("organ");
String pubdata=rs.getString("pubdata");
String type=rs.getString("type");
String id=rs.getString("id");
%>
<tbody>
<tr>
<td><%=name %></td>
<td><%=organ %></td>
<td><%=pubdata %></td>
<td><%=type %></td>
<td><a href="policyDetails.jsp?policyId=<%= id %>">查看</a></td>
</tr>
<% }
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try{
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}
catch( SQLException e){
e.printStackTrace();
}
}
%>
</tbody>
</table>
</section>
</div>
<footer class="footer">
<p>Copyright 1996-2022 All Rights Reserved 版权所有:河北省科学技术情报研究院 河北省科技创新战略研究院 技术支持:河北省科技信息处理实验室</p>
</footer>
</body>
</html>
<%!
// Helper method to convert advanced search query to regex
private String convertToRegex(String query) {
if (query == null || query.isEmpty()) {
return "";
}
// Replace operators with regex equivalents
query = query.replace(" * ", ".*");
query = query.replace(" + ", "|");
query = query.replace(" - ", "(?!.*");
// Handle special cases for quotes and parentheses
query = query.replaceAll("'([^']*)'", "$1");
query = query.replaceAll("\"([^\"]*)\"", "$1");
query = query.replaceAll("\\(", "(");
query = query.replaceAll("\\)", ")");
return query;
}
%>
浙公网安备 33010602011771号