首页 > 其他分享 >今天课上实现了一个简陋的web项目-河北科技政策查询系统

今天课上实现了一个简陋的web项目-河北科技政策查询系统

时间:2023-04-10 23:35:58浏览次数:45  
标签:web 分页 pageSize 简陋 课上 num tempStr var endRow

test.jsp

<%@ 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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ page import="java.sql.*"%>
<title>www.jb51.net JS分页</title>
<script>
/**
 * 分页函数
 * pno--页数
 * psize--每页显示记录数
 * 分页部分是从真实数据行开始,因而存在加减某个常数,以确定真正的记录数
 * 纯js分页实质是数据行全部加载,通过是否显示属性完成分页功能
 **/
function goPage(pno,psize){
  var itable = document.getElementById("idData");
  var num = itable.rows.length;//表格所有行数(所有记录数)
  console.log(num);
  var totalPage = 0;//总页数
  var pageSize = 15;//每页显示行数
  //总共分几页
  if(num/pageSize > parseInt(num/pageSize)){
      totalPage=parseInt(num/pageSize)+1;
    }else{
      totalPage=parseInt(num/pageSize);
    }
  var currentPage = pno;//当前页数
  var startRow = (currentPage - 1) * pageSize+1;//开始显示的行 31
    var endRow = currentPage * pageSize;//结束显示的行  40
    endRow = (endRow > num)? num : endRow;  //40
    console.log(endRow);
    //遍历显示数据实现分页
  for(var i=1;i<(num+1);i++){
    var irow = itable.rows[i-1];
    if(i>=startRow && i<=endRow){
      irow.style.display = "block";
    }else{
      irow.style.display = "none";
    }
  }
  var tempStr = "共"+num+"条记录 分"+totalPage+"页 当前第"+currentPage+"页";
  if(currentPage>1){
    tempStr += "<a href=\"#\" onClick=\"goPage("+(1)+","+psize+")\">首页</a>";
    tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage-1)+","+psize+")\"><上一页</a>"
  }else{
    tempStr += "首页";
    tempStr += "<上一页";
  }
  if(currentPage<totalPage){
    tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage+1)+","+psize+")\">下一页></a>";
    tempStr += "<a href=\"#\" onClick=\"goPage("+(totalPage)+","+psize+")\">尾页</a>";
  }else{
    tempStr += "下一页>";
    tempStr += "尾页";
  }
  document.getElementById("barcon").innerHTML = tempStr;
}
</script>
</head>
<body onl oad="goPage(1,10);">
<form action="jieguo1.jsp">
<table id="idData"  border="1px" align="center" width="100%" height="80%">
<tr align="center"><td   colspan="5"><img src="LOGO.png"  wideth="20" height="20"> 科技政策查询系统</td></tr>
<tr align="center"><td width="20%" height="20%">政策名称:  <input type="text" name="name"      /></td>
<td width="20%" height="20%">发文字号:  <input type="text" name="document"      />  </td>
<td width="20%" height="20%">发文机构:  <input type="text" name="organ"       />  </td>
<td width="20%" height="20%">全文检索:  <input type="text" name="text1"     />  </td>
<td width="20%" height="20%"><input   type="submit"   value="查询"/><!--提交  value内的内容是按键内内容--></td>
</tr>
<tr align="center"><td width="25%" height="20%">政策名称: </td>
<td width="25%" height="20%">发文机构:   </td>
<td width="25%" height="20%">颁布时间:    </td>
<td  colspan="2" width="25%" height="20%">政策分类:   </td>
</tr>
<% 
String a=request.getParameter("name");
String b=request.getParameter("document");
String c=request.getParameter("organ");
String d=request.getParameter("text1");

String URL = "jdbc:mysql://localhost:3306/info ";
String USERNAME = "root";
String PWD = "PENGsuoqun123";

        //jsp就是在html中嵌套的java代码,因此java代码可以写在jsp中(《%%》)
    PreparedStatement pstmt = null;
    ResultSet rs=null;
            Connection connection = null;
            
            try {

                // a.导入驱动,加载具体驱动类

                Class.forName("com.mysql.cj.jdbc.Driver");//注册// 加载具体的驱动类
                // b.与数据库建立链接
                connection = DriverManager.getConnection(URL, USERNAME, PWD);
                String sql ="select * from policy " ;
                
                pstmt=connection.prepareStatement(sql);
            
                
                                
                                
                                
                                
                                
                                
                                rs= pstmt.executeQuery();// 反回值,增删改了几条数据增删改用update
                                
                                
                                while(rs.next()) {
                                    //政策名称
                                        String name=rs.getString("name");
                                         //发文机构
                                         String organ=rs.getString("organ");
                                         //颁布时间
                                         String pubdata=rs.getString("pubdata");
                                         //政策分类
                                         String type=rs.getString("type");
                                        
                                        
                                        %>
                                        
                            
                                    
                                        
                                        
                                
                                        <tr align="center">
                                        <td width="20%" height="20%"><a href="neirong.jsp?name=<%=name %>"><%out.print(name);%></td>
                                        
                                        <td width="20%" height="20%"><%out.print(organ);%></td>
                                        <td width="20%" height="20%"><%out.print(pubdata);%></td>
                                        
                                        <td  colspan="2" width="20%" height="20%"><%out.print(type);%></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();
                
                }
                
                
            }



%>
</table>
</form>
  <table width="60%" align="center">
    <tr><td><div id="barcon" name="barcon"></div></td></tr>
  </table>
</body>
</html>

jieguo1.jsp

<%@ 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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ page import="java.sql.*"%>
<title>www.jb51.net JS分页</title>
<script>
/**
 * 分页函数
 * pno--页数
 * psize--每页显示记录数
 * 分页部分是从真实数据行开始,因而存在加减某个常数,以确定真正的记录数
 * 纯js分页实质是数据行全部加载,通过是否显示属性完成分页功能
 **/
function goPage(pno,psize){
  var itable = document.getElementById("idData");
  var num = itable.rows.length;//表格所有行数(所有记录数)
  console.log(num);
  var totalPage = 0;//总页数
  var pageSize = 15;//每页显示行数
  //总共分几页
  if(num/pageSize > parseInt(num/pageSize)){
      totalPage=parseInt(num/pageSize)+1;
    }else{
      totalPage=parseInt(num/pageSize);
    }
  var currentPage = pno;//当前页数
  var startRow = (currentPage - 1) * pageSize+1;//开始显示的行 31
    var endRow = currentPage * pageSize;//结束显示的行  40
    endRow = (endRow > num)? num : endRow;  //40
    console.log(endRow);
    //遍历显示数据实现分页
  for(var i=1;i<(num+1);i++){
    var irow = itable.rows[i-1];
    if(i>=startRow && i<=endRow){
      irow.style.display = "block";
    }else{
      irow.style.display = "none";
    }
  }
  var tempStr = "共"+num+"条记录 分"+totalPage+"页 当前第"+currentPage+"页";
  if(currentPage>1){
    tempStr += "<a href=\"#\" onClick=\"goPage("+(1)+","+psize+")\">首页</a>";
    tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage-1)+","+psize+")\"><上一页</a>"
  }else{
    tempStr += "首页";
    tempStr += "<上一页";
  }
  if(currentPage<totalPage){
    tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage+1)+","+psize+")\">下一页></a>";
    tempStr += "<a href=\"#\" onClick=\"goPage("+(totalPage)+","+psize+")\">尾页</a>";
  }else{
    tempStr += "下一页>";
    tempStr += "尾页";
  }
  document.getElementById("barcon").innerHTML = tempStr;
}
</script>
</head>
<body onl oad="goPage(1,10);">
<table id="idData"  border="1px" align="center" width="100%" height="80%">
<tr align="center"><td   colspan="5"><img src="LOGO.png"  wideth="20" height="20"> 科技政策查询系统</td></tr>
<tr align="center"><td width="20%" height="20%">政策名称:  <input type="text" name="name"      /></td>
<td width="20%" height="20%">发文字号:  <input type="text" name="document"      />  </td>
<td width="20%" height="20%">发文机构:  <input type="text" name="organ"       />  </td>
<td width="20%" height="20%">全文检索:  <input type="text" name="text1"     />  </td>
<td width="20%" height="20%"><input   type="submit"   value="查询"/><!--提交  value内的内容是按键内内容--></td>
</tr>
<tr align="center"><td width="25%" height="20%">政策名称: </td>
<td width="25%" height="20%">发文机构:   </td>
<td width="25%" height="20%">颁布时间:    </td>
<td  colspan="2" width="25%" height="20%">政策分类:   </td>
</tr>
<% 
String a=request.getParameter("name");
String b=request.getParameter("document");
String c=request.getParameter("organ");
String d=request.getParameter("text1");

String URL = "jdbc:mysql://localhost:3306/info ";
String USERNAME = "root";
String PWD = "PENGsuoqun123";

        //jsp就是在html中嵌套的java代码,因此java代码可以写在jsp中(《%%》)
    PreparedStatement pstmt = null;
    ResultSet rs=null;
            Connection connection = null;
            
            try {

                // a.导入驱动,加载具体驱动类

                Class.forName("com.mysql.cj.jdbc.Driver");//注册// 加载具体的驱动类
                // b.与数据库建立链接
                connection = DriverManager.getConnection(URL, USERNAME, PWD);
                String sql ="select * from policy where name like ? and  document like  ? and organ like ? and text like ?" ;
                
                pstmt=connection.prepareStatement(sql);
            
                pstmt.setString(1, "%"+a+"%");
                pstmt.setString(2, "%"+b+"%");
                pstmt.setString(3, "%"+c+"%");
                pstmt.setString(4, "%"+d+"%");
                                
                                
                                
                                
                                
                                
                                rs= pstmt.executeQuery();// 反回值,增删改了几条数据增删改用update
                                
                                
                                while(rs.next()) {
                                    //政策名称
                                        String name=rs.getString("name");
                                         //发文机构
                                         String organ=rs.getString("organ");
                                         //颁布时间
                                         String pubdata=rs.getString("pubdata");
                                         //政策分类
                                         String type=rs.getString("type");
                                        
                                        
                                        %>
                                        
                            
                                    
                                        
                                        
                                
                                        <tr align="center">
                                        <td width="20%" height="20%"><a href="neirong.jsp?name=<%=name %>"><%out.print(name);%></td>
                                        
                                        <td width="20%" height="20%"><%out.print(organ);%></td>
                                        <td width="20%" height="20%"><%out.print(pubdata);%></td>
                                        
                                        <td  colspan="2" width="20%" height="20%"><%out.print(type);%></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();
                
                }
                
                
            }



%>
</table>
  <table width="60%" align="center">
    <tr><td><div id="barcon" name="barcon"></div></td></tr>
  </table>
</body>
</html>

neirong.jsp

<%@ page language= "java" contentType= "text/html; charset=UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<head>
<meta charset="UTF-8" >
<%@ page import="java.sql.*"%>
<title>内容展示页面</title>
</head>
<body>
<table border="1px" align="center">
  <%
    String name= request.getParameter("name");
%>
<%out.print(name); %></td></tr>


<%
String URL = "jdbc:mysql://localhost:3306/info ";
String USERNAME = "root";
String PWD = "PENGsuoqun123";

        //jsp就是在html中嵌套的java代码,因此java代码可以写在jsp中(《%%》)
    PreparedStatement pstmt = null;
    ResultSet rs=null;
            Connection connection = null;
            
            try {

                // a.导入驱动,加载具体驱动类

                Class.forName("com.mysql.cj.jdbc.Driver");//注册// 加载具体的驱动类
                // b.与数据库建立链接
                connection = DriverManager.getConnection(URL, USERNAME, PWD);
                String sql ="select * from policy where name like ? " ;
                
                pstmt=connection.prepareStatement(sql);
            
                pstmt.setString(1, "%"+name+"%");
        
                                
                                
                                
                                
                                
                                
                                rs= pstmt.executeQuery();// 反回值,增删改了几条数据增删改用update
                                
                                
                                while(rs.next()) {
                                    //政策名称
                                        String text=rs.getString("text");
                                         
                                        
                                        
                                        out.print(text);}     

        

                
            }
             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();
                
                }
                
                
            }








%>







</table>

</body>

 

标签:web,分页,pageSize,简陋,课上,num,tempStr,var,endRow
From: https://www.cnblogs.com/pengsuoqun123/p/17304729.html

相关文章

  • ASP.NET Web API]如何Host定义在独立程序集中的Controller
    原文:https://www.cnblogs.com/artech/p/custom-assembly-resolver.html通过《ASP.NETWebAPI的Controller是如何被创建的?》的介绍我们知道默认ASP.NETWebAPI在SelfHost寄宿模式下用于解析程序集的AssembliesResolver是一个DefaultAssembliesResolver对象,它只会提供当前应用程......
  • 课上测试-科技政策查询系统(实现分页显示和模糊查询)
    今天的软工课上,老师给我们布置了课堂小测试,要求我们做一个简单的科技政策查询系统,具体要能实现模糊查询和分页显示。老师没有要求我们完成数据结构和树形结构分类,总体还是比较容易的。 代码请见我下一篇博客:https://www.cnblogs.com/rsy-bxf150/p/17304267.html题目要......
  • 课上测试-实现分页显示和模糊查询(代码部分)
    今天的软工课上,老师给我们布置了课堂小测试,要求我们做一个简单的科技政策查询系统,具体要能实现模糊查询和分页显示。这里展示我实现的代码。目前实现了基本功能,还有点小不完善,之后再改一改吧。Query.javapackagemain;importdao.Bean;importdatas.DB;importj......
  • ctfshow web入门 sql注入 171-175
    171-175同属无过滤绕过(并未对sql语句过滤,仅对查询结果过滤)重点:1、了解万能密码2、了解sql语句中字符串函数3、了解备份功能(导入/导出数据)4、蚁剑如何连接数据库web171$sql="selectusername,passwordfromuserwhereusername!='flag'andid=......
  • 常见webeshell工具流量分析
    中国菜刀虚拟机使用仅主机模式,开启apache服务,使用wireshark对此网卡进行抓包  追踪http数据流  base64解码得出<?php@ini_set("display_errors","0");@set_time_limit(0);if(PHP_VERSION<'5.3.0'){@set_magic_quotes_runtime(0);};echo("X@Y&qu......
  • SIP视频监控 / webrtc视频会议接入GB28181国标平台
     截图使用的是知乎视频 实现思路:1.使用国标代理网关,建立sip号码与gb28181设备号,通道号之间的对照表,实现gb28181网关功能(设备注册,目录查询,心跳,直播拉流,Bye,设备注销),参:GB28181国标代理-CHHC-博客园(cnblogs.com)2.直播拉流时,可通过调用sip系统/视频会议系统提供发送RTP......
  • WebAssembly 助力云原生:APISIX 如何借助 Wasm 插件实现扩展功能?
    本文将介绍Wasm,以及ApacheAPISIX如何实现Wasm功能。作者朱欣欣,API7.ai技术工程师原文链接什么是WasmWasm是WebAssembly的缩写。WebAssembly/Wasm是一个基于堆栈的虚拟机设计的指令格式。在Wasm未出现之前,浏览器中只能支持运行Javascript语言。当Wasm出现......
  • SpringMVC怎么实现web端上传超大文件
    ​ 一、功能性需求与非功能性需求要求操作便利,一次选择多个文件和文件夹进行上传;支持PC端全平台操作系统,Windows,Linux,Mac 支持文件和文件夹的批量下载,断点续传。刷新页面后继续传输。关闭浏览器后保留进度信息。支持文件夹批量上传下载,服务器端保留文件夹层级结构,服务......
  • 前端怎么实现web端上传超大文件
    ​ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现。下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压。ASP.NET页面设计:TextBox和Button按钮。​编辑TextBox中需要自己受到输入文件夹的路径(包含文件夹),通过Button实......
  • Webpack中手动实现Loader与Plugin
    Loaderloader是一个转换器,用于对源代码进行转换。工作流程webpack.config.js里配置了一个模块的Loader;2.遇到相应模块文件时,触发了该模块的loader;3.loader接受了一个表示该模块文件内容的source;4.loader使用webapck提供的一系列api对source进行转换,......