5.6

科技政策查询系统

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/xinwen ";
String USERNAME = "root";
String PWD = "a123456";

//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>


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.*"%>
<link rel="Shortcut Icon" href="images/LOGO.png">
<title>科学政策查询系统</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 = 10;//每页显示行数
//总共分几页
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 onLoad="goPage(1,10);">
<div style="text-align: center; font-family: '微软雅黑'; font-size: 30pt;">
<img src="images/LOGO.png" id="logo" style="vertical-align: middle; width: 50px; height: 50px;">
科技政策查询系统
</div>
<br/>
<table border="0px" align="center" width="100%" height="100%" >

<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>
</table>
<br>
<table border="0px" width="100%" height="100%" style="background-color: #d1dce3; font-size: 16px;">
<tr align="center">
<td width="20%" height="40%">政策名称</td>
<td width="20%" height="40%">发文机构</td>
<td width="20%" height="40%">颁布日期</td>
<td width="20%" height="40%">政策分类</td>
<td colspan="2" width="20%" height="40%">操作</td>

</tr>
</table>
<table id="idData" border="0px" align="center" width="100%" height="100%">


<%
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/xinwen ";
String USERNAME = "root";
String PWD = "a123456";

//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%"><%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>

<td width="20%" height="20%"><a href="neirong.jsp?name=<%=name %>"><%out.print("查看");%></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();

}

}

%>
</table>
<table width="60%" align="center">
<tr><td><div id="barcon" name="barcon"></div></td></tr>
</table>
</body>
</html>
posted @ 2024-05-07 17:12  涨涨涨张  阅读(20)  评论(0编辑  收藏  举报