校园社团活动管理系统(20分)
1、项目需求:
校园社团作为高校课外活动的重要组成部分,发展十分迅速,也受到越来越多学生的欢迎,社团规模、数量等都在日益增长,社团活动也更为多样和丰富。然而,大多数高校还没有一个完整成熟的社团管理系统,仅仅是靠人力来管理,导致效率低下,而学生也只能通过线下或者公众号的方式了解社团,另外,社团活动的通知方式也很杂乱,并没有一个信息聚合、消息发布的平台。
因此,高校有必要建立一个校园社团管理系统,使得社团管理工作规范化、系统化、程序化、科学化,提高管理工作的效率。
2.系统要求与功能设计
2.1 页面功能要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)
(2)网站页面整体风格统一;
图1 活动普查系统功能结构图
(3)主页面:要求显示发布活动信息、修改活动信息、删除活动信息、查询活动信息,活动信息浏览五个子菜单。(1分)
(4)发布活动信息页面:(6分)
①完成添加活动信息发布,基本信息和填报限制如下表所示
活动主题 |
字符串(不超过20个汉字) |
活动目的 |
字符串(不超过50个汉字) |
活动类型 |
社团竞赛、野外采风、校内集会、社团纳新(单选框) |
活动时间 |
文本框 |
活动地点 |
文本框 |
活动对象 |
社团成员、全体学生(复选框实现) |
活动内容 |
(文本框,不超过500个汉字) |
活动日程安排 |
(文本框,不超过500个汉字) |
②点击“提交”按钮,保存成功则跳转到活动基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面
评分标准:
① 完成活动信息发布页面(未完成0分,完成1分)
② 保存活动信息入库(未完成0分,完成1分)
③ 社团竞赛、野外采风、校内集会、社团纳新实现单选框录入1分。(未完成0分,全部完成1分)
④ 实现活动对象复选框录入1分。(未完成0分,完成1分)
⑤ 实现活动主题、活动目的、活动内容、活动日程安排的字数判断,实现三个以上得1分(未完成0分,完成1分)
⑥提交后页面跳转功能;(未完成0分,完成1分)
(5)修改活动信息页面:(3分)
输入活动主题,显示其余信息,可对活动目的、活动类型、活动时间、活动地点、活动对象、活动内容、活动日程安排进行修改。(活动目的、活动类型、活动时间、活动地点、活动对象、活动内容、活动日程安排必须符合录入要求);如果该活动主题数据库不存在,则提示“该活动不存在”。(3分)
评分标准:
① 完成修改活动信息页面(未完成0分,完成1分)
② 实现数据库中信息更新(未完成0分,完成1分)
③输入活动主题,显示其余信息,若该信息不存在,提示错误信息;(未完成0分,完成1分)
(6)删除活动信息页面:录入活动主题,显示详细信息后,点击“删除”按钮,弹出提示框,提示“是否确认删除该活动信息”,确认后删除该信息。(1分)
评分标准:
① 输入活动主题可显示其余信息。(未完成0分,完成0.5分)
②对应删除数据库中信息(未完成0分,完成0.5分)
(7)浏览活动信息页面:(2分)
以列表形式显示活动基本信息,结果列表中显示活动主题、活动时间,活动类型、活动对象基本信息,点击主题,可以跳转到活动详细信息,显示全部活动信息。
① 实现以列表形式显示活动基本信息,结果列表中显示活动主题、活动时间,活动类型、活动对象基本信息(未完成0分,完成1分)
②实现跳转活动详细信息页面,显示全部活动信息。(未完成0分,完成1分)
(8)查询活动信息页面:(3分)
要求根据活动主题、活动时间、活动类型、活动地点四种条件实现模糊查询,输出结果以列表形式显示,显示显示活动主题、活动时间,活动类型、活动对象基本信息,点击列表中的活动主题,跳转到活动详细信息页面。
评分标准:
①缺少一种查询条件扣除1分。(未完成0分,完成3分)
2.2 功能要求
(1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种(1分)
(2)使用Serverlet实现页面交互(1分)。
(3)使用Java Bean封装数据库连接操作(1分。)
项目结构
![](/i/l/?n=22&i=blog/2913422/202210/2913422-20221029182047644-642506572.png)
数据库表
![](/i/l/?n=22&i=blog/2913422/202210/2913422-20221029182148036-955264422.png)
bean.java
package Bean;
public class bean
{
private String zhuti;
private String mudi;
private String leixing;
private String shijian;
private String didian;
private String duixiang;
private String neirong;
private String anpai;
public String getZhuti()
{
return zhuti;
}
public void setZhuti(String zhuti)
{
this.zhuti = zhuti;
}
public String getMudi()
{
return mudi;
}
public void setMudi(String mudi)
{
this.mudi = mudi;
}
public String getLeixing()
{
return leixing;
}
public void setLeixing(String leixing)
{
this.leixing = leixing;
}
public String getShijian()
{
return shijian;
}
public void setShijian(String shijian)
{
this.shijian = shijian;
}
public String getDidian()
{
return didian;
}
public void setDidian(String didian)
{
this.didian = didian;
}
public String getDuixiang()
{
return duixiang;
}
public void setDuixiang(String duixiang)
{
this.duixiang = duixiang;
}
public String getNeirong()
{
return neirong;
}
public void setNeirong(String neirong)
{
this.neirong = neirong;
}
public String getAnpai()
{
return anpai;
}
public void setAnpai(String anpai)
{
this.anpai = anpai;
}
}
dao.java
package Dao;
import Bean.bean;
import Util.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class dao
{
public void adddata(bean bean)//增
{
Connection connection= util.getConnection();
PreparedStatement preparedStatement=null;
try
{
String sql="insert into activity(主题,目的,类型,时间,地点,对象,内容,日程安排) values(?,?,?,?,?,?,?,?)";
preparedStatement =connection.prepareStatement(sql);
preparedStatement.setString(1,bean.getZhuti());
preparedStatement.setString(2,bean.getMudi());
preparedStatement.setString(3,bean.getLeixing());
preparedStatement.setString(4,bean.getShijian());
preparedStatement.setString(5,bean.getDidian());
preparedStatement.setString(6,bean.getDuixiang());
preparedStatement.setString(7,bean.getNeirong());
preparedStatement.setString(8,bean.getAnpai());
preparedStatement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
util.close(preparedStatement);
util.close(connection);
}
}
public void delete(String zhuti)//删
{
Connection connection=util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "delete from activity where 主题= ?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,zhuti);
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}
public void changedata( String zhuti,String mudi,String leixing,String shijian,String didian,String duixiang,String neirong,String anpai)
{
//改
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "update activity set 目的=?, 类型=?, 时间=?, 地点=?, 对象=? , 内容=? , 日程安排=? where 主题=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,mudi);
preparedStatement.setString(2,leixing);
preparedStatement.setString(3,shijian);
preparedStatement.setString(4,didian);
preparedStatement.setString(5,duixiang);
preparedStatement.setString(6,neirong);
preparedStatement.setString(7,anpai);
preparedStatement.setString(8,zhuti);
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}
}
util.java
package Util;
import java.sql.*;
public class util
{
public static Connection getConnection()//连接数据库
{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
//System.out.println("加载驱动成功");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="root";
String password="Mendy030628";
String url = "jdbc:mysql://localhost:3306/db1?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true";
Connection con=null;
try{
con= DriverManager.getConnection(url,user,password);
//System.out.println("数据库连接成功");
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
//**********************************************************************
//关闭方法
public static void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
}
}
add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>发布活动信息</title>
</head>
<body>
<form action="add_back.jsp" method="get">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
主题
<input type="text" name="zhuti" >
<br>
目的
<input type="text" name="mudi" >
<br>
类型
<input type="radio" name="leixing" value="社团竞赛">社团竞赛
<input type="radio" name="leixing" value="野外采风">野外采风
<input type="radio" name="leixing" value="校内集会">校内集会
<input type="radio" name="leixing" value="社团纳新">社团纳新
<br>
时间
<input type="text" name="shijian" >
<br>
地点
<input type="text" name="didian" >
<br>
对象
<input type="checkbox" name="duixiang" value="社团成员">社团成员
<input type="checkbox" name="duixiang" value="全体学生">全体学生
<br>
内容
<input type="text" name="neirong" maxlength="500">
<br>
日程安排
<input type="text" name="anpai" maxlength="500">
<br>
<input type="submit" value="提交" >
<input type="reset" value="重置" >
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">
</p>
</form>
</body>
</html>
add_back.jsp
<%@ page import="java.sql.SQLException" %>
<%@ page import="Bean.bean" %>
<%@ page import="Dao.dao" %>
<%@ page language= "java" import="java.util.*" contentType= "text/html; charset=UTF-8"
pageEncoding= "UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta charset="UTF-8">
<%
String zhuti = request.getParameter("zhuti");
String mudi = request.getParameter("mudi");
String leixing = request.getParameter("leixing");
String shijian = request.getParameter("shijian");
String didian = request.getParameter("didian");
String [] h = request.getParameterValues("duixiang");
String duixiang = Arrays.toString(h);
duixiang = duixiang.substring(1, duixiang.length()-1);
String neirong = request.getParameter("neirong");
String anpai = request.getParameter("anpai");
if(zhuti=="")
{
out.print("<script language='javaScript'> alert('活动主题输入为空'); window.history.back(); </script>");
}
else if(zhuti.length()>20)
{
out.print("<script language='javaScript'> alert('活动主题超过20字,请修改'); window.history.back(); </script>");
}
else if(mudi=="")
{
out.print("<script language='javaScript'> alert('活动目的输入为空'); window.history.back(); </script>");
}
else if(mudi.length()>50)
{
out.print("<script language='javaScript'> alert('活动目的超过50字,请修改'); window.history.back(); </script>");
}
else if(leixing=="")
{
out.print("<script language='javaScript'> alert('活动类型输入为空'); window.history.back(); </script>");
}
else if(shijian=="")
{
out.print("<script language='javaScript'> alert('活动时间输入为空'); window.history.back(); </script>");
}
else if(didian=="")
{
out.print("<script language='javaScript'> alert('活动地点输入为空'); window.history.back(); </script>");
}
else if(duixiang=="")
{
out.print("<script language='javaScript'> alert('活动对象输入为空'); window.history.back(); </script>");
}
else if(neirong=="")
{
out.print("<script language='javaScript'> alert('活动内容输入为空'); window.history.back(); </script>");
}
else if(neirong.length()>500)
{
out.print("<script language='javaScript'> alert('活动内容超过500字,请修改'); window.history.back(); </script>");
}
else if(anpai=="")
{
out.print("<script language='javaScript'> alert('日程安排输入为空'); window.history.back(); </script>");
}
else if(anpai.length()>500)
{
out.print("<script language='javaScript'> alert('日程安排超过500字,请修改'); window.history.back(); </script>");
}
else
{
bean bean = new bean();
bean.setZhuti(zhuti);
bean.setMudi(mudi);
bean.setLeixing(leixing);
bean.setShijian(shijian);
bean.setDidian(didian);
bean.setDuixiang(duixiang);
bean.setNeirong(neirong);
bean.setAnpai(anpai);
dao dao = new dao();
dao.adddata(bean);
out.print("<script language='javaScript'> alert('添加成功');</script>");
response.setHeader("refresh", "0;url=list_part.jsp");
}
%>
</html>
change.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>活动信息修改</title>
</head>
<body>
<form action="change_back_1.jsp">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
请输入要修改的活动的主题
<br>
<input type="text" name="zhuti">
<br>
<input type="submit" value="提交">
<input type="reset" value="重置">
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">
</p>
</form>
</body>
</html>
change_back_1.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<%
String zhuti=(String)request.getParameter("zhuti");
session.setAttribute("zhuti",zhuti);
%>
<table border="1"cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=10%>目的</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>时间</td>
<td align="center" width=10%>地点</td>
<td align="center" width=10%>对象</td>
<td align="center" width=10%>内容</td>
<td align="center" width=10%>日程安排</td>
</tr>
<%
int i=0;
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from activity";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(zhuti.equals(rs.getObject(1)))
{
i++;
%>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
<td align="center"><%=rs.getObject(8) %></td>
</tr>
<%
}
}
if(i==0)
{
out.print("<script language='javaScript'> alert('该活动不存在'); window.history.back(-1); </script>");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<form action="change_back_2.jsp" method="get">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<br>
<br>
修改信息
<br>
目的
<input type="text" name="mudi" maxlength="50">
<br>
类型
<input type="radio" name="leixing" value="社团竞赛">社团竞赛
<input type="radio" name="leixing" value="野外采风">野外采风
<input type="radio" name="leixing" value="校内集会">校内集会
<input type="radio" name="leixing" value="社团纳新">社团纳新
<br>
时间
<input type="text" name="shijian" >
<br>
地点
<input type="text" name="didian" >
<br>
对象
<input type="checkbox" name="duixiang" value="社团成员">社团成员
<input type="checkbox" name="duixiang" value="全体学生">全体学生
<br>
内容
<input type="text" name="neirong" maxlength="500">
<br>
日程安排
<input type="text" name="anpai" maxlength="500">
<br>
<br><input type="submit" value="提交" />
<input type="reset" value="重置" /> <br>
<br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</form>
</body>
</html>
change_back_2.jsp
<%@ page import="Dao.dao" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<%
String zhuti=(String)session.getAttribute("zhuti");
String mudi=(String)request.getParameter("mudi");
String leixing=(String)request.getParameter("leixing");
String shijian=(String)request.getParameter("shijian");
String didian=(String)request.getParameter("didian");
String duixiang=(String)request.getParameter("duixiang");
String neirong=(String)request.getParameter("neirong");
String anpai=(String)request.getParameter("anpai");
if(mudi=="")
{
out.print("<script language='javaScript'> alert('活动目的输入为空'); window.history.back(); </script>");
}
else if(mudi.length()>50)
{
out.print("<script language='javaScript'> alert('活动目的超过50字,请修改'); window.history.back(); </script>");
}
else if(leixing=="")
{
out.print("<script language='javaScript'> alert('活动类型输入为空'); window.history.back(); </script>");
}
else if(shijian=="")
{
out.print("<script language='javaScript'> alert('活动时间输入为空'); window.history.back(); </script>");
}
else if(didian=="")
{
out.print("<script language='javaScript'> alert('活动地点输入为空'); window.history.back(); </script>");
}
else if(duixiang=="")
{
out.print("<script language='javaScript'> alert('活动对象输入为空'); window.history.back(); </script>");
}
else if(neirong=="")
{
out.print("<script language='javaScript'> alert('活动内容输入为空'); window.history.back(); </script>");
}
else if(neirong.length()>500)
{
out.print("<script language='javaScript'> alert('活动内容超过500字,请修改'); window.history.back(); </script>");
}
else if(anpai=="")
{
out.print("<script language='javaScript'> alert('日程安排输入为空'); window.history.back(); </script>");
}
else if(anpai.length()>500)
{
out.print("<script language='javaScript'> alert('日程安排超过500字,请修改'); window.history.back(); </script>");
}
else
{
dao dao=new dao();
dao.changedata(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai);
out.print("<script language='javaScript'> alert('修改成功');</script>");
response.setHeader("refresh", "0;url=change.jsp");
}
%>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
delete.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>活动信息删除</title>
</head>
<body>
<form action="delete_back_1.jsp" method="get">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
请输入要删除的活动的主题
<br>
<input type="text" name="zhuti">
<br>
<input type="submit" value="提交" >
<input type="reset" value="重置" >
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">
<br>
</p>
</form>
</body>
</html>
delete_back_1.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<%
String zhuti = (String)request.getParameter("zhuti");
session.setAttribute("zhuti", zhuti);
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from activity";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(zhuti.equals(rs.getObject(1)))
{
%>
<table border="1"cellspacing="0"style="text-align:center;">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=10%>目的</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>时间</td>
<td align="center" width=10%>地点</td>
<td align="center" width=10%>对象</td>
<td align="center" width=10%>内容</td>
<td align="center" width=10%>日程安排</td>
</tr>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
<td align="center"><%=rs.getObject(8) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" value="删除" onclick="location.href='delete_back_2.jsp'" />
<br>
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
delete_back_2.jsp
<%@ page import="Dao.dao" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>删除</title>
</head>
<body>
<script>
function del()
{
var r = confirm("确定要删除吗?")
if (r == true)
{
return true;
}
else
{
return false;
}
}
del();
</script>
<%
dao dao=new dao();
String zhuti=(String)session.getAttribute("zhuti");//注意
dao.delete(zhuti);
out.print("<script language='javaScript'> alert('删除成功');</script>");
response.setHeader("refresh", "0;url=delete.jsp");
%>
</body>
</html>
list_all.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<%
String zhuti = (String)request.getParameter("zhuti");
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from activity";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(zhuti.equals(rs.getObject(1)))
{
%>
<table border="1"cellspacing="0"style="text-align:center;">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=10%>目的</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>时间</td>
<td align="center" width=10%>地点</td>
<td align="center" width=10%>对象</td>
<td align="center" width=10%>内容</td>
<td align="center" width=10%>日程安排</td>
</tr>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
<td align="center"><%=rs.getObject(8) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back(-1);" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
list_part.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>基本信息浏览</title>
</head>
<body>
<table border="1" cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=6%>时间</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>对象</td>
</tr>
<%
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from activity";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
%>
<tr>
<td align="center"><a href='list_all.jsp?zhuti=<%=rs.getObject(1)%>'><%=rs.getObject(1) %></a></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(6) %></td>
</tr>
<%
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>主菜单</title>
</head>
<form action="#" method="get">
<p style="text-align:center;font-size:20px" >
校园社团活动管理系统
<br>
<input type="button" value="发布活动信息" onclick="location.href='add.jsp'" /><br>
<input type="button" value="修改活动信息" onclick="location.href='change.jsp'" /><br>
<input type="button" value="删除活动信息" onclick="location.href='delete.jsp'" /><br>
<input type="button" value="查询活动信息" onclick="location.href='search.jsp'" /><br>
<input type="button" value="浏览活动信息" onclick="location.href='list_part.jsp'" /><br>
<br>
</p>
</form>
</html>
search.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>活动信息查询</title>
</head>
<body>
<form action="search_part.jsp" method="get">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
请输入要查询的活动主题/时间/类型/地点(模糊查询)
<br>
<input type="text" name="data">
<br>
<input type="submit" value="提交" >
<input type="reset" value="重置" >
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">
<br>
</p>
</form>
</body>
</html>
search_all.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<%
String zhuti = (String)request.getParameter("zhuti");
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from activity";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(zhuti.equals(rs.getObject(1)))
{
%>
<table border="1"cellspacing="0"style="text-align:center;">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=10%>目的</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>时间</td>
<td align="center" width=10%>地点</td>
<td align="center" width=10%>对象</td>
<td align="center" width=10%>内容</td>
<td align="center" width=10%>日程安排</td>
</tr>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
<td align="center"><%=rs.getObject(8) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
search_part.jsp
<%@ page import="java.sql.Connection" %>标签:preparedStatement,javaweb,期中考试,back,zhuti,util,活动,String From: https://www.cnblogs.com/mendianyu/p/16839347.html
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="Util.util" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>部分信息</title>
</head>
<body>
<%
String data=(String)request.getParameter("data");
if(data=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else
{
%>
<table border="1" cellspacing="0">
<tr>
<td align="center" width=6%>主题</td>
<td align="center" width=6%>时间</td>
<td align="center" width=6%>类型</td>
<td align="center" width=6%>对象</td>
</tr>
<%
int i=0;
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql= " select * from activity where 主题 like ? or 时间 like ? or 类型 like ? or 地点 like ? ";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,"%"+data+"%");
preparedStatement.setString(2,"%"+data+"%");
preparedStatement.setString(3,"%"+data+"%");
preparedStatement.setString(4,"%"+data+"%");
rs=preparedStatement.executeQuery();
while(rs.next())
{
i++;
%>
<tr>
<td align="center"><a href='search_all.jsp?zhuti=<%=rs.getObject(1)%>'><%=rs.getObject(1) %></a></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(6) %></td>
</tr>
<%
}
if(i==0)
{
out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" >
<br>
</p>
</body>
</html>
问题:信息浏览新录入的信息置顶显示未实现