2022期中考试
校园社团活动管理系统(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分。)
本次实验用到了下列代码,缺少数据回显以及先执行查询后删除的功能,后续会继续优化减少代码页数同时完成后续功能
com.Bean文件下的jia.java和jian.java
package com.Bean; public class jia { private String zhuti; private String mudi; private String leixing; private String time; private String didian; private String name; private String neirong; private String anapi; 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 getTime() { return time; } public void setTime(String time) { this.time = time; } public String getDidian() { return didian; } public void setDidian(String didian) { this.didian = didian; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNeirong() { return neirong; } public void setNeirong(String neirong) { this.neirong = neirong; } public String getAnapi() { return anapi; } public void setAnapi(String anapi) { this.anapi = anapi; } }
package com.Bean; public class jian { String zhuti; public String getZhuti() { return zhuti; } public void setZhuti(String zhuti) { this.zhuti = zhuti; } }
com.Dao文件下的xg.java,sc.java以及tianjia.java代码如下
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jian; import com.Util.utils; public class sc { // TODO Auto-generated method stub public int delete(jian A) throws Exception { Connection connection = utils.getConnection(); String sql = "delete from huodong where zhuti=?";//删除你的表格内容 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getZhuti()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } return i; } }
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jia; import com.Util.utils; public class tianjia{ // TODO Auto-generated method stub public int add(jia A) throws Exception { Connection connection = utils.getConnection(); String sql = "insert into huodong values(?,?,?,?,?,?,?,?)";//修改你的表格名称 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getZhuti()); preparedStatement.setString(2, A.getMudi()); preparedStatement.setString(3, A.getLeixing()); preparedStatement.setString(4, A.getTime()); preparedStatement.setString(5,A.getDidian()); preparedStatement.setString(6, A.getName()); preparedStatement.setString(7, A.getNeirong()); preparedStatement.setString(8, A.getAnapi()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } return i; } }
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jia; import com.Util.utils; public class xg{ // TODO Auto-generated method stub public int update(jia A) throws Exception { Connection connection = utils.getConnection(); String sql = "update huodong set mudi=?,leixing=?,time=?,didian=?,name=?,neirong=?,anpai=? where zhuti=?";//修改你的表格名称 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getMudi()); preparedStatement.setString(2, A.getLeixing()); preparedStatement.setString(3, A.getTime()); preparedStatement.setString(4,A.getDidian()); preparedStatement.setString(5, A.getName()); preparedStatement.setString(6, A.getNeirong()); preparedStatement.setString(7, A.getAnapi()); preparedStatement.setString(8, A.getZhuti()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } return i; } }
com.Util下的utils工具包
package com.Util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * JDBC快速入门 */ public class utils { public static Connection getConnection() throws Exception { Connection connection = null;//连接数据库 PreparedStatement ps = null;//Statement 对象用于将 SQL 语句发送到数据库中。 ResultSet rs = null; //1. 导入驱动jar包 //2.注册驱动 // Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/zjr?serverTimezone=UTC","root", "Zhaowenzhe1007");//修改你的数据库名称以及密码 return connection; } public static void close(Connection connection ) { try { if (connection != null) { connection.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(PreparedStatement preparedStatement ) { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(ResultSet resultSet ) { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Serlvet交互工具
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.tianjia; import com.Bean.jia; /** * Servlet implementation class dengji */ @WebServlet("/dengji")//对应html中的action表单 public class dengji extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 tianjia A =new tianjia(); int i = 0; String zhuti=request.getParameter("zhuti"); String mudi = request.getParameter("mudi"); String leixing = request.getParameter("leixing"); String time = request.getParameter("time"); String didian = request.getParameter("didian"); String name = request.getParameter("name"); String neirong = request.getParameter("neirong"); String anpai = request.getParameter("anpai"); jia B = new jia(); B.setZhuti(zhuti); B.setMudi(mudi); B.setLeixing(leixing); B.setTime(time); B.setDidian(didian); B.setName(name); B.setNeirong(neirong); B.setAnapi(anpai); try { i=A.add(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("发布成功!"); else response.getWriter().append("发布失败!"); } }
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.sc; import com.Bean.jian; /** * Servlet implementation class dengji */ @WebServlet("/dengji1")//对应html中的action表单 public class dengji1 extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji1() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 sc A =new sc(); int i = 0; String zhuti = request.getParameter("zhuti"); jian B = new jian(); B.setZhuti(zhuti); try { i=A.delete(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("删除成功!"); else response.getWriter().append("删除失败,请检查是否存在此活动!"); } }
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.xg; import com.Bean.jia; /** * Servlet implementation class dengji */ @WebServlet("/dengji2")//对应html中的action表单 public class dengji2 extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji2() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 xg A =new xg(); int i = 0; String zhuti=request.getParameter("zhuti"); String mudi = request.getParameter("mudi"); String leixing = request.getParameter("leixing"); String time = request.getParameter("time"); String didian = request.getParameter("didian"); String name = request.getParameter("name"); String neirong = request.getParameter("neirong"); String anpai = request.getParameter("anpai"); jia B = new jia(); B.setZhuti(zhuti); B.setMudi(mudi); B.setLeixing(leixing); B.setTime(time); B.setDidian(didian); B.setName(name); B.setNeirong(neirong); B.setAnapi(anpai); // System.out.println(B.getHubie()); // System.out.println(B.getName()); // System.out.println(B.getSex()); // System.out.println(B.getNumber()); // System.out.println(B.getJiaoyu()); // System.out.println(B.getId()); try { i=A.update(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("修改成功!"); else response.getWriter().append("修改失败,请检查是否存在问题!"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
页面
<%@ page language="java" 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>
<head>
<title>校园社团活动管理系统</title>
</head>
<body>
<form action="dengji.html" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="发布活动信息" />
</table>
</p>
</form>
<form action="xiugai.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="修改活动信息" />
</table>
</p>
</form>
<form action="shanchu.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="删除活动信息" />
</table>
</p>
</form>
<form action="chaxun.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="查询活动信息" />
</table>
</p>
</form>
<form action="liulan.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="浏览所有活动信息" />
</table>
</p>
</form>
</body>
</html>
<%@ page language="java" 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>
<head>
<title>校园社团活动管理系统</title>
</head>
<body>
<form action="dengji.html" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="发布活动信息" />
</table>
</p>
</form>
<form action="xiugai.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="修改活动信息" />
</table>
</p>
</form>
<form action="shanchu.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="删除活动信息" />
</table>
</p>
</form>
<form action="chaxun.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="查询活动信息" />
</table>
</p>
</form>
<form action="liulan.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="浏览所有活动信息" />
</table>
</p>
</form>
</body>
</html>
<%@ page language="java" 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>
<head>
<title>用户查询页面</title>
</head>
<body>
<tr>
<form action="chaxun1.jsp" method="get">
<table align="center" border="1" width="500">
<td>请输入需要查询的活动类型 : </td>
<td>
<input type="text" name="leixing" size="12" maxlength="20" />
</td>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="查询">
</div>
</td>
</tr>
</form>
<form action="chaxun2.jsp" method="get">
<table align="center" border="1" width="500">
<td>请输入需要查询的活动主题 : </td>
<td>
<input type="text" name="zhuti" size="12" maxlength="20" />
</td>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="查询">
</div>
</td>
</tr>
</form>
<form action="chaxun3.jsp" method="get">
<table align="center" border="1" width="500">
<td>请输入需要查询的活动时间 : </td>
<td>
<input type="text" name="time" size="12" maxlength="20" />
</td>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="查询">
</div>
</td>
</tr>
</form>
<form action="chaxun4.jsp" method="get">
<table align="center" border="1" width="500">
<td>请输入需要查询的活动地点 : </td>
<td>
<input type="text" name="didian" size="12" maxlength="20" />
</td>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="查询">
</div>
</td>
</tr>
</form>
<tr>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String leixing = request.getParameter("leixing"); //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select *from huodong where huodong.leixing like '%"+leixing+"%';"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("活动主题: "+rs.getString("zhuti")+"   "+"活动时间: "+rs.getString("time")+"   "+"活动类型: "+rs.getString("leixing")+"   "+"活动地点: "+rs.getString("didian")+"   "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String zhuti = request.getParameter("zhuti"); //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select *from huodong where huodong.zhuti like '%"+zhuti+"%';"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("活动主题: "+rs.getString("zhuti")+"   "+"活动时间: "+rs.getString("time")+"   "+"活动类型: "+rs.getString("leixing")+"   "+"活动地点: "+rs.getString("didian")+"   "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String time = request.getParameter("time"); //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select *from huodong where huodong.time like '%"+time+"%';"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("活动主题: "+rs.getString("zhuti")+"   "+"活动时间: "+rs.getString("time")+"   "+"活动类型: "+rs.getString("leixing")+"   "+"活动地点: "+rs.getString("didian")+"   "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String didian = request.getParameter("didian"); //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select *from huodong where huodong.didian like '%"+didian+"%';"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("活动主题: "+rs.getString("zhuti")+"   "+"活动时间: "+rs.getString("time")+"   "+"活动类型: "+rs.getString("leixing")+"   "+"活动地点: "+rs.getString("didian")+"   "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select * from huodong;"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("活动主题: "+rs.getString("zhuti")+"   "+"活动目的: "+rs.getString("mudi")+"   "+"活动类型: "+rs.getString("leixing")+"   "+"活动时间: "+rs.getString("time")+"   "+"活动地点: "+rs.getString("didian")+"   "+"活动对象: "+rs.getString("name")+"   "+"活动内容: "+rs.getString("neirong")+"   "+"活动日程安排: "+rs.getString("anpai")+"   "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
<%@ page language="java" 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"> <%@ page import="java.sql.*"%> <html > <head> <title>用户删除页面</title> </head> <body> <tr> <form action="dengji1" method="post"> <table align="center" border="1" width="500"> <td>请输入需要删除的活动主题 : </td> <td> <input type="text" name="zhuti" size="12" maxlength="20"/> <td colspan="2"><div align="center"> <input onclick=" return confirm('是否确认删除')" type="submit" value="删除"> <input type="hidden" value="zhuti" name="zhuti"> </td> </form> </tr> <tr> </div> </td> </tr> </form> <tr> </body> </html>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="GB18030">
<title>Insert title here</title>
</head>
<body>
<tr>
<form action="xiugai1.html" method="get">
<table align="center" border="1" width="500">
<td>请输入需要修改的活动主题 : </td>
<td>
<input type="text" name="zhuti" size="12" maxlength="20"/>
</td>
</form>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="修改信息">
</div>
</td>
</tr>
<tr>
</body>
</html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>发布页面</title> </head> <body> <div align="center"> <form action="dengji2" method="post"> <tr> <font face="楷体" size="7" color="pink">修改活动信息页面</font> </tr> <tr> <td>当前活动主题:</td> <td> <input type="text" name="zhuti"> </tr> <table align="center"> <tr> <td>活动目的(不超过50个汉字):</td> <td> <input type="text" name="mudi"> </tr> <tr> <td>活动类型:</td> <td> <input type="radio" name="leixing" value="社团竞赛">社团竞赛 <input type="radio" name="leixing" value="野外采风" >野外采风 <input type="radio" name="leixing" value="校内集会"checkd>校内集会 <input type="radio" name="leixing" value="社团纳新">社团纳新 </td> </tr> <tr> <td>活动时间:</td> <td> <input type="text" name="time"> </tr> <tr> <td>活动地点:</td> <td> <input type="text" name="didian"> </tr> <tr> <td>活动对象:</td> <td> <input type="checkbox" name="name" value="社团成员">社团成员 <input type="checkbox" name="name" value="全体学生">全体学生 </td> </tr> <tr> <td>活动内容(不超过500个汉字):</td> <td> <input type="text" name="neirong"> </tr> <tr> <td>活动日程安排(不超过500个汉字):</td> <td> <input type="text" name="anpai"> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="提交"> </div> </td> </tr> </form> </div> </body> </html>
本次代码模糊查询还没来得及实践,不然可以将其融合到一起进行选择摘取,模糊查询视频可见
下面是代码实现截图