4.20
所花时间:6小时
代码量:92
博客篇:1
web实现政策查询
servlet1
import javaClass.Dao; import javaClass.policy; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; @WebServlet("/Servlet1") public class Servlet1 extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String name=req.getParameter("name"); String document = req.getParameter("document"); String organ = req.getParameter("organ"); String text = req.getParameter("text"); String v1=req.getParameter("v1"); String v2=req.getParameter("v2"); String v3=req.getParameter("v3"); String v4=req.getParameter("v4"); Dao d =new Dao(); ArrayList<policy> a=new ArrayList<>(500); try { a=d.check(name,document,organ,text,v1,v2,v3,v4); } catch (SQLException e) { throw new RuntimeException(e); } HttpSession session = req.getSession(true); session.setMaxInactiveInterval(10*60); session.setAttribute("data",a); resp.sendRedirect("/policyCheck_war/check.jsp"); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); } }
check.jsp
<%@ page import="javaClass.policy" %> <%@ page import="javaClass.SessionUtils" %> <%@ page import="java.util.ArrayList" %><%-- Created by IntelliJ IDEA. User: 86132 Date: 2024/4/30 Time: 16:23 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% ArrayList<policy> a=new ArrayList<>(500); a= SessionUtils.getSession1(request); %> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>查询</title> <link rel="stylesheet" type="text/css" href="./css/main1.css"/> <link rel="stylesheet" href="css/side.css"> </head> <body onload="first_click()"> <script type="text/javascript"> // 定义一个数组,保存当前所有页面的class name var page_index = []; for (var i=0;i<100;i++){ page_index[i]="page-"+i.toString(); } // 输入pagename,打开指定的div,隐藏其他的div function page_option(pagename){ var tar_index = page_index.indexOf(pagename); page_index.slice(tar_index, 1); for (var j = 0; j < page_index.length ; j++) { var close_div = document.getElementsByClassName(page_index[j]); for (var i = 0; i < close_div.length; i++) { close_div[i].style.display = "none"; } ; } var opendiv = document.getElementsByClassName(pagename); for (var i = 0; i<opendiv.length;i++) { opendiv[i].style.display="block"; }; } // 点击 返回第一页按钮 执行的操作 function first_click(){ page_option("page-1"); document.getElementById('currentPage').value=1; } // 点击 跳到最后一页按钮 执行的操作 function last_click(){ var total_page = document.getElementById('totalPage').value; page_option(page_index[<%=a.size()/10%>]); document.getElementById('currentPage').value=total_page; } // 点击 上一页按钮 执行的操作 function prev_click(){ var cur_page = document.getElementById('currentPage').value; if (cur_page > 1){ document.getElementById('currentPage').value=parseInt(cur_page)-1; var pagename = page_index[parseInt(cur_page)-2]; page_option(pagename); } } // 点击 下一页按钮 执行的操作 function next_click(){ var cur_page = document.getElementById('currentPage').value; var total_page = document.getElementById('totalPage').value; if (cur_page < total_page){ document.getElementById('currentPage').value=parseInt(cur_page) + 1; var pagename = page_index[parseInt(cur_page)]; page_option(pagename); } } // 手动改变当前页码时执行的操作 function choose_page(){ var cur_page = document.getElementById('currentPage').value; var pagename = page_index[parseInt(cur_page)-1]; page_option(pagename); } // 鼠标事件,经过每一条资讯时改变标题的颜色 function light(obj){ obj.firstElementChild.style.color="#FF9900"; } function normal(obj){ obj.firstElementChild.style.color="#000000"; } </script> <div class="page-block"> <div style="text-align: center"> <img src="LOGO.png" height="70" width="70" style="overflow: hidden"> <h1>科技政策查询系统</h1> </div> <hr> <div style="display: block"> <form action="/policyCheck_war/Servlet1" method="post" style="text-align: center" name="form1"> 政策名称:<input type="text" name="name"> <select name="v1"> <option value="like">模糊</option> <option value="=">精确</option> </select><br> 政策文号:<input type="text" name="document"> <select name="v2"> <option value="like">模糊</option> <option value="=">精确</option> </select><br> 发文机构:<input type="text" name="organ"> <select name="v3"> <option value="like">模糊</option> <option value="=">精确</option> </select><br> 全文检索:<input type="text" name="text"> <select name="v4"> <option value="like">模糊</option> <option value="=">精确</option> </select> <input type="submit" value="搜索"> </form> </div> <hr> <% int n=1; int num=a.size()/10; int i=0; while (n<=num+1){ %> <div class="page-<%=n%>"> <p> 查询到了<%=a.size()%>条数据</p> <table> <tr> <table border="0" cellpadding="10" style=" border-left-color: #B0C4DE; border-bottom-color: #B0C4DE; width: 100%;border-top-style: solid; border-top-color: #B0C4DE; border-right-style: solid; border-left-style: solid; height: 250px; border-right-color: #B0C4DE; border-bottom-style: solid"> <tr> <th align="center" bgcolor="#F0FFFF" ><%="政策名称"%></th> <th align="center" bgcolor="#F0FFFF" ><%="发文机构"%></th> <th align="center" bgcolor="#F0FFFF" ><%="颁布日期"%></th> <th align="center" bgcolor="#F0FFFF" ><%="政策分类"%></th> <th align="center" bgcolor="#F0FFFF" ><%="操作"%></th> </tr> <% %> <% //arr.size() while (a.size()>i&&i<10+(n-1)*10&&i>=(n-1)*10){ %> <tr> <td align="center" bgcolor="#F5F5F5"><%=a.get(i).getName()%></td> <td align="center" bgcolor="#F5F5F5"><%=a.get(i).getOrgan()%></td> <td align="center" bgcolor="#F5F5F5"><%=a.get(i).getViadata()%></td> <td align="center" bgcolor="#F5F5F5"><%=a.get(i).getType()%></td> <td align="center" bgcolor="#f5f5dc"><a href="index.jsp?n=<%=i%>">查看详情</a></td> </tr> <% i++; } %> </table> </td> </tr> </table> </div> <% n++; } %> </div> <div class="page-icon"> <button class="firstPage" onclick="first_click()" >首页</button> <button class="beforePage" onclick="prev_click()" >上一页</button> <button>第<input id="currentPage" onchange="choose_page()" type="text" value="1"/>页</button> <button>/ 共<input id="totalPage" type="button" value=<%=num+1%> readonly="readonly">页</button> <button class="nextPage" onclick="next_click()">下一页</button> <button class="lastPage" onclick="last_click()">尾页</button> </div> </body> </html>