期中考试题目:
校园社团活动管理系统(20分)
1、项目需求:
校园社团作为高校课外活动的重要组成部分,发展十分迅速,也受到越来越多学生的欢迎,社团规模、数量等都在日益增长,社团活动也更为多样和丰富。然而,大多数高校还没有一个完整成熟的社团管理系统,仅仅是靠人力来管理,导致效率低下,而学生也只能通过线下或者公众号的方式了解社团,另外,社团活动的通知方式也很杂乱,并没有一个信息聚合、消息发布的平台。
因此,高校有必要建立一个校园社团管理系统,使得社团管理工作规范化、系统化、程序化、科学化,提高管理工作的效率。
2.系统要求与功能设计
2.1 页面功能要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)
(2)网站页面整体风格统一;
图1 活动普查系统功能结构图
(3)主页面:要求显示发布活动信息、修改活动信息、删除活动信息、查询活动信息,活动信息浏览五个子菜单。(1分)
(4)发布活动信息页面:(6分)
①完成添加活动信息发布,基本信息和填报限制如下表所示
活动主题 |
字符串(不超过20个汉字) |
活动目的 |
字符串(不超过50个汉字) |
活动类型 |
社团竞赛、野外采风、校内集会、社团纳新(单选框) |
活动时间 |
文本框 |
活动地点 |
文本框 |
活动对象 |
社团成员、全体学生(复选框实现) |
活动内容 |
(文本框,不超过500个汉字) |
活动日程安排 |
(文本框,不超过500个汉字) |
②点击“提交”按钮,保存成功则跳转到活动基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面
我的代码:
1.test.Data.java
package test; import java.sql.*; import java.util.regex.Pattern; public class Data { private String topic,objective,active_type,time,place,person,content,schedule; public void setTopic(String topic) { this.topic = topic; } public String getTopic() { return topic; } public String getObjective() { return objective; } public void setObjective(String objective) { this.objective = objective; } public String getActive_type() { return active_type; } public void setActive_type(String active_type) { this.active_type = active_type; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getPlace() { return place; } public void setPlace(String place) { this.place = place; } public String getPerson() { return person; } public void setPerson(String person) { this.person = person; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getSchedule() { return schedule; } public void setSchedule(String schedule) { this.schedule = schedule; } //Util //*********************************************************************** public Connection getConnection()//连接数据库 { try{ Class.forName("com.mysql.cj.jdbc.Driver"); //System.out.println("加载驱动成功"); }catch(ClassNotFoundException e) { e.printStackTrace(); } String user="root"; String password="352204"; String url = "jdbc:mysql://localhost:3306/us_schedule?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 void close (Connection con) { try{ if(con!=null) { con.close(); } }catch(SQLException e) { e.printStackTrace(); } } public void close (PreparedStatement preparedStatement) { try{ if(preparedStatement!=null) { preparedStatement.close(); } }catch(SQLException e) { e.printStackTrace(); } } public void close(ResultSet resultSet) { try{ if(resultSet!=null) { resultSet.close(); } }catch(SQLException e) { e.printStackTrace(); } } //Dao //****************************************************************** //增 public void add_data(String topic,String objective,String active_type,String time,String place,String person,String content,String schedule) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { String sql = "insert into active(活动主题, 活动目的, 活动类型, 活动时间, 活动地点, 活动对象, 活动内容, 活动日程安排) values (?,?,?,?,?,?,?,?)"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,topic); preparedStatement.setString(2,objective); preparedStatement.setString(3,active_type); preparedStatement.setString(4,time); preparedStatement.setString(5,place); preparedStatement.setString(6,person); preparedStatement.setString(7,content); preparedStatement.setString(8,schedule); preparedStatement.executeUpdate(); //System.out.println("添加成功"); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //删 public void delete_data(String topic) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { String sql = "delete from active where 活动主题 = ?"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,topic); preparedStatement.executeUpdate(); //System.out.println("删除成功"); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //改 public void revise_data(String topic1,String topic,String objective,String active_type,String time,String place,String person,String content,String schedule) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { String sql = "update active set 活动主题=?,活动目的=?, 活动类型=?,活动时间=?,活动地点=?,活动对象=?,活动内容=?,活动日程安排=? where 活动主题=?"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,topic); preparedStatement.setString(2,objective); preparedStatement.setString(3,active_type); preparedStatement.setString(4,time); preparedStatement.setString(5,place); preparedStatement.setString(6,person); preparedStatement.setString(7,content); preparedStatement.setString(8,schedule); preparedStatement.setString(9,topic1); preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //判断方法**************************************************************** //判空 public boolean isEmpty(String topic,String objective,String active_type,String time,String place,String person,String content,String schedule) { if(topic==null||objective==null||active_type==""||time==""||place==""||person==""||content==null||schedule=="") return true; else return false; } public boolean isactivesame(String topic, String active_type, String time, String place) { Connection connection = getConnection(); PreparedStatement preparedStatement = null; ResultSet rs = null; try { String sql = "select * from active"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); while (rs.next()) { if (topic.equals(rs.getObject(1)) &&active_type.equals(rs.getObject(3))&&time.equals(rs.getObject(4))&&place.equals(rs.getObject(5))) return true; } //preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { close(rs); close(preparedStatement); close(connection); } return false; } //判重/判存在 public boolean isSame(String s) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from active"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(s.equals(rs.getObject(1))) return true; } //preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally{ close(rs); close(preparedStatement); close(connection); } return false; } }
2.menu.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>主菜单</title> 8 </head> 9 <body> 10 <p style="text-align:center;color:black;font-family:宋体; font-size:20px"> 11 校园社团活动管理系统 12 <br> 选择功能: 13 <br> 14 <input type="button" value="发布活动信息" onclick="location.href='add.jsp'" /> 15 <br/> 16 <input type="button" value="删除活动信息" onclick="location.href='delete.jsp'" /> 17 <br/> 18 <input type="button" value="修改活动信息" onclick="location.href='revise.jsp'" /> 19 <br/> 20 <input type="button" value="查询活动信息" onclick="location.href='search.jsp'" /> 21 <br/> 22 <input type="button" value="浏览活动信息" onclick="location.href='show.jsp'" /> 23 <br> 24 </p> 25 </body> 26 </html>
3.add.jsp
1 <%@page import="test.Data"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>登记</title> 9 </head> 10 <body> 11 <form action="add2.jsp" method="get"> 12 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 13 活动登记页面 14 <br>活动主题<input type="text" name="topic" maxlength="20"><br> 15 <br>活动目的<input type="text" name="objective" maxlength="50"><br> 16 <br>活动类型 17 <select name="active_type"> 18 <option selected="selected">请选择</option> 19 <option value="社团竞赛">社团竞赛</option> 20 <option value="野外采风">野外采风</option> 21 <option value="校内集会">校内集会</option> 22 <option value="社团纳新">社团纳新</option> 23 </select><br> 24 <br>活动时间<input type="text" name="time"/><br> 25 <br>活动地点 <input type="text" name="place"/><br> 26 <br>活动对象 27 <input type="checkbox" name="person_1" value="社团成员" />社团成员 28 <input type="checkbox" name="person_2" value="全体学生" />全体学生<br> 29 <br>活动内容<input type="text" name="content" maxlength="500"><br> 30 <br>活动日程安排<input type="text" name="schedule" maxlength="500"><br> 31 <br><input type="submit" value="提交" /> 32 <input type="reset" value="重置" /> <br> 33 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 34 </p> 35 </form> 36 </body> 37 </html>
4.add2.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>主菜单</title> 8 </head> 9 <body> 10 <p style="text-align:center;color:black;font-family:宋体; font-size:20px"> 11 校园社团活动管理系统 12 <br> 选择功能: 13 <br> 14 <input type="button" value="发布活动信息" onclick="location.href='add.jsp'" /> 15 <br/> 16 <input type="button" value="删除活动信息" onclick="location.href='delete.jsp'" /> 17 <br/> 18 <input type="button" value="修改活动信息" onclick="location.href='revise.jsp'" /> 19 <br/> 20 <input type="button" value="查询活动信息" onclick="location.href='search.jsp'" /> 21 <br/> 22 <input type="button" value="浏览活动信息" onclick="location.href='show.jsp'" /> 23 <br> 24 </p> 25 </body> 26 </html>
5.delete.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>删除</title> 8 </head> 9 <body> 10 <form action="delete2.jsp" method="get"> 11 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 12 活动删除页面 13 <br> 要删除活动主题: <input type="text" name="topic" /> <br> 14 <br><input type="submit" value="确定" /> 15 <input type="reset" value="重置" /> 16 <br> 17 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 18 </p> 19 </form> 20 </body> 21 </html> 22 6.delete2.jsp 23 24 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 25 pageEncoding="UTF-8"%> 26 <!DOCTYPE html> 27 <html> 28 <head> 29 <meta charset="UTF-8"> 30 </head> 31 <body> 32 33 <jsp:useBean id="util" class="test.Data" scope="page" /> 34 <% 35 String topic=(String)request.getParameter("topic"); 36 if(topic==""){ 37 out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); 38 }else if(!util.isSame(topic)) 39 { 40 out.print("<script language='javaScript'> alert('该住户不存在'); window.history.back(-1); </script>"); 41 } else{ 42 %> 43 <table border="1"style="text-align:center;"> 44 <tr> 45 <td align="center" width=10%>活动主题</td> 46 <td align="center" width=10%>活动目的</td> 47 <td align="center" width=10%>活动类型</td> 48 <td align="center" width=10%>活动时间</td> 49 <td align="center" width=10%>活动地点</td> 50 <td align="center" width=15%>活动对象</td> 51 <td align="center" width=10%>活动内容</td> 52 <td align="center" width=10%>活动日程安排</td> 53 <td align="center" width=5%>删除</td> 54 </tr> 55 <% 56 Connection connection = util.getConnection(); 57 PreparedStatement preparedStatement=null; 58 ResultSet rs=null; 59 try { 60 String sql = "select * from active"; 61 preparedStatement=connection.prepareStatement(sql); 62 rs=preparedStatement.executeQuery(); 63 while(rs.next()){ 64 if(topic.equals(rs.getObject(1))) 65 { 66 %> 67 <tr> 68 <td align="center"><%=rs.getObject(1) %></td> 69 <td align="center"><%=rs.getObject(2) %></td> 70 <td align="center"><%=rs.getObject(3) %></td> 71 <td align="center"><%=rs.getObject(4) %></td> 72 <td align="center"><%=rs.getObject(5) %></td> 73 <td align="center"><%=rs.getObject(6) %></td> 74 <td align="center"><%=rs.getObject(7) %></td> 75 <td align="center"><%=rs.getObject(8) %></td> 76 <td align="center"><a style="color:blue" href='delete3.jsp?topic=<%=rs.getObject(1) %>' onclick="javascript:return del()">删除</a> </td> 77 </tr> 78 79 <% 80 } 81 } 82 } catch (SQLException e) { 83 e.printStackTrace(); 84 }finally{ 85 util.close(rs); 86 util.close(preparedStatement); 87 util.close(connection); 88 } 89 %> 90 </table> 91 <% 92 } 93 %> 94 <script> 95 function del(){ 96 var r = confirm("确定要删除吗?") 97 if (r == true) { 98 return true; 99 } else { 100 return false; 101 } 102 } 103 </script> 104 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 105 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 106 </p> 107 </body> 108 </html>
7.delete3.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <input type="button" onclick="openResult()" value="删除"/> 10 <jsp:useBean id="util" class="test.Data" scope="page" /> 11 <% 12 String topic=(String)request.getParameter("topic"); 13 util.delete_data(topic); 14 out.print("<script language='javaScript'> alert('删除成功');</script>"); 15 response.setHeader("refresh", "0;url=delete.jsp"); 16 %> 17 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 18 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 19 </p> 20 </body> 21 </html>
8.revise.jsp
1 <%@page import="test.Data"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>登记</title> 9 </head> 10 <body> 11 <form action="revise1.jsp" method="get"> 12 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 13 <br> 输入要修改的活动主题 <input type="text" name="topic" /><br> 14 <br><input type="submit" value="提交" /> 15 <input type="reset" value="重置" /> <br> 16 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 17 </p> 18 </form> 19 </body> 20 </html>
9.revise1.jsp
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>修改</title> 8 </head> 9 <body> 10 11 <jsp:useBean id="util" class="test.Data" scope="page" /> 12 <% 13 String topic=(String)request.getParameter("topic"); 14 if(topic==""){ 15 out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); 16 } 17 else if(!util.isSame(topic)) 18 { 19 out.print("<script language='javaScript'> alert('该活动不存在'); window.history.back(-1); </script>"); 20 } 21 else{ 22 %> 23 <table border="1"style="text-align:center;"> 24 <tr> 25 <td align="center" width=6%>活动主题</td> 26 <td align="center" width=8%>活动目的</td> 27 <td align="center" width=10%>活动类型</td> 28 <td align="center" width=10%>活动时间</td> 29 <td align="center" width=6%>活动地点</td> 30 <td align="center" width=18%>活动对象</td> 31 <td align="center" width=3%>活动内容</td> 32 <td align="center" width=10%>活动日程安排</td> 33 <td align="center" width=3%>修改</td> 34 </tr> 35 <% 36 Connection connection = util.getConnection(); 37 PreparedStatement preparedStatement=null; 38 ResultSet rs=null; 39 try { 40 String sql = "select * from active"; 41 preparedStatement=connection.prepareStatement(sql); 42 rs=preparedStatement.executeQuery(); 43 while(rs.next()){ 44 if(topic.equals(rs.getObject(1))) 45 { 46 %> 47 <tr> 48 <td align="center"><%=rs.getObject(1) %></td> 49 <td align="center"><%=rs.getObject(2) %></td> 50 <td align="center"><%=rs.getObject(3) %></td> 51 <td align="center"><%=rs.getObject(4) %></td> 52 <td align="center"><%=rs.getObject(5) %></td> 53 <td align="center"><%=rs.getObject(6) %></td> 54 <td align="center"><%=rs.getObject(7) %></td> 55 <td align="center"><%=rs.getObject(8) %></td> 56 <td align="center"><a style="color:blue" href='revise2.jsp?topic1=<%=rs.getObject(1) %>active_type=<%=rs.getObject(3) %>time=<%=rs.getObject(4) %>place=<%=rs.getObject(5) %>'>修改</a> </td> 57 </tr> 58 <% 59 } 60 } 61 } catch (SQLException e) { 62 e.printStackTrace(); 63 }finally{ 64 util.close(rs); 65 util.close(preparedStatement); 66 util.close(connection); 67 } 68 %> 69 </table> 70 <% 71 } 72 %> 73 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 74 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 75 </p> 76 </body> 77 </html>
10.revise2.jsp
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <jsp:useBean id="util" class="test.Data" scope="page" /> 10 <% 11 String topic1=(String)request.getParameter("topic1"); 12 session.setAttribute("topic1",topic1); 13 %> 14 <table border="1"style="text-align:center;"> 15 <tr> 16 <td align="center" width=6%>活动主题</td> 17 <td align="center" width=8%>活动目的</td> 18 <td align="center" width=10%>活动类型</td> 19 <td align="center" width=10%>活动时间</td> 20 <td align="center" width=6%>活动地点</td> 21 <td align="center" width=18%>活动对象</td> 22 <td align="center" width=3%>活动内容</td> 23 <td align="center" width=10>活动日程安排</td> 24 </tr> 25 <% 26 Connection connection = util.getConnection(); 27 PreparedStatement preparedStatement=null; 28 ResultSet rs=null; 29 try { 30 String sql = "select * from active"; 31 preparedStatement=connection.prepareStatement(sql); 32 rs=preparedStatement.executeQuery(); 33 while(rs.next()){ 34 if(topic1.equals(rs.getObject(1))) 35 { 36 %> 37 <tr> 38 <td align="center"><%=rs.getObject(1) %></td> 39 <td align="center"><%=rs.getObject(2) %></td> 40 <td align="center"><%=rs.getObject(3) %></td> 41 <td align="center"><%=rs.getObject(4) %></td> 42 <td align="center"><%=rs.getObject(5) %></td> 43 <td align="center"><%=rs.getObject(6) %></td> 44 <td align="center"><%=rs.getObject(7) %></td> 45 <td align="center"><%=rs.getObject(8) %></td> 46 </tr> 47 <% 48 } 49 } 50 } catch (SQLException e) { 51 e.printStackTrace(); 52 }finally{ 53 util.close(rs); 54 util.close(preparedStatement); 55 util.close(connection); 56 } 57 %> 58 </table> 59 60 <form action="revise3.jsp" method="get"> 61 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 62 活动登记页面 63 <br>活动主题<input type="text" name="topic" maxlength="20"><br> 64 <br>活动目的<input type="text" name="objective" maxlength="50"><br> 65 <br>活动类型 66 <select name="active_type"> 67 <option selected="selected">请选择</option> 68 <option value="社团竞赛">社团竞赛</option> 69 <option value="野外采风">野外采风</option> 70 <option value="校内集会">校内集会</option> 71 <option value="社团纳新">社团纳新</option> 72 </select><br> 73 <br>活动时间<input type="text" name="time"/><br> 74 <br>活动地点 <input type="text" name="place"/><br> 75 <br>活动对象 76 <input type="checkbox" name="person_1" value="社团成员" />社团成员 77 <input type="checkbox" name="person_2" value="社团成员" />全体学生<br> 78 <br>活动内容<input type="text" name="content" maxlength="500"><br> 79 <br>活动日程安排<input type="text" name="schedule"><br> 80 <br><input type="submit" value="提交" /> 81 <input type="reset" value="重置" /> <br> 82 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 83 </p> 84 </form> 85 </body> 86 </html>
11.revise3.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <jsp:useBean id="util" class="test.Data" scope="page" /> 10 <% 11 String topic1=(String)session.getAttribute("topic1"); 12 String topic=(String)request.getParameter("topic"); 13 String objective=(String)request.getParameter("objective"); 14 String active_type=(String)request.getParameter("active_type"); 15 String time=(String)request.getParameter("time"); 16 String place=(String)request.getParameter("place"); 17 String person_1=null; 18 String person_2=null; 19 if(request.getParameter("person_1")!=null) 20 { 21 person_1=request.getParameter("person_1")+' '; 22 } 23 else person_1=" "; 24 if(request.getParameter("person_2")!=null) 25 { 26 person_2=request.getParameter("person_2")+' '; 27 } 28 else person_2=" "; 29 String person=person_1+person_2; 30 String content=(String)request.getParameter("content"); 31 String schedule=(String)request.getParameter("schedule"); 32 if(util.isEmpty(topic,objective,active_type,time,place,person,content,schedule)){ 33 out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); 34 }else if (util.isactivesame(topic,active_type,time,place)) { 35 out.print("<script language='javaScript'> alert('活动重复');window.history.back(-1);</script>"); 36 } else 37 { 38 util.revise_data(topic1,topic,objective,active_type,time,place,person,content,schedule); 39 out.print("<script language='javaScript'> alert('修改成功');</script>"); 40 response.setHeader("refresh", "0;url=revise.jsp"); 41 } 42 %> 43 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 44 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 45 </p> 46 </body> 47 </html>
12.search.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>查询</title> 8 </head> 9 <body> 10 <form action="search2.jsp" method="get"> 11 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 12 输入要查询信息的活动主题/活动类型/活动时间/活动地点(支持模糊查询): 13 <br> <input type="text" name="data" /> <br> 14 <br><input type="submit" value="提交" /> 15 <input type="reset" value="重置" /> <br> 16 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 17 </p> 18 </form> 19 </body> 20 </html>
13.search2.jsp
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>查询</title> 8 </head> 9 <body> 10 查询结果 11 <p> 12 <jsp:useBean id="util" class="test.Data" scope="page" /> 13 <% 14 String data=(String)request.getParameter("data"); 15 if(data==""){ 16 out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); 17 } 18 else 19 { 20 %> 21 <table border="1"style="text-align:center;"> 22 <tr> 23 <td align="center" width=6%>活动查询</td> 24 </tr> 25 <% 26 int i=0; 27 Connection connection = util.getConnection(); 28 PreparedStatement preparedStatement=null; 29 ResultSet rs=null; 30 try { 31 String sql= "select * from active where 活动主题 like ? or 活动类型 like ? or 活动时间 like ? or 活动地点 like ? "; 32 preparedStatement=connection.prepareStatement(sql); 33 preparedStatement.setString(1,"%"+data+"%"); 34 preparedStatement.setString(2,"%"+data+"%"); 35 preparedStatement.setString(3,"%"+data+"%"); 36 preparedStatement.setString(4,"%"+data+"%"); 37 rs=preparedStatement.executeQuery(); 38 while(rs.next()) 39 { 40 i++; 41 %> 42 <tr> 43 <td align="center"><a style="color:blue" href='search3.jsp?topic=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a> </td> 44 <td align="center"><%=rs.getObject(3) %></td> 45 <td align="center"><%=rs.getObject(4) %></td> 46 <td align="center"><%=rs.getObject(5) %></td> 47 </tr> 48 <% 49 } 50 if(i==0) 51 { 52 out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>"); 53 } 54 } catch (SQLException e) { 55 e.printStackTrace(); 56 }finally{ 57 util.close(rs); 58 util.close(preparedStatement); 59 util.close(connection); 60 } 61 } 62 %> 63 </table> 64 65 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 66 <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 67 </p> 68 </body> 69 </html>
14.search3.jsp
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>详细信息</title> 8 </head> 9 <body> 10 11 12 <jsp:useBean id="util" class="test.Data" scope="page" /> 13 14 <% 15 String topic = (String)request.getParameter("topic"); 16 Connection connection = util.getConnection(); 17 PreparedStatement preparedStatement=null; 18 ResultSet rs=null; 19 try { 20 String sql = "select * from active"; 21 preparedStatement=connection.prepareStatement(sql); 22 rs=preparedStatement.executeQuery(); 23 while(rs.next()){ 24 if(topic.equals(rs.getObject(1))) 25 { 26 %> 27 <table border="1"style="text-align:center;"> 28 <tr> 29 <td align="center" width=6%>活动主题</td> 30 <td align="center" width=8%>活动目的</td> 31 <td align="center" width=10%>活动类型</td> 32 <td align="center" width=10%>活动时间</td> 33 <td align="center" width=6%>活动地点</td> 34 <td align="center" width=18%>活动对象</td> 35 <td align="center" width=3%>活动内容</td> 36 <td align="center" width=10>活动日程安排</td> 37 </tr> 38 <tr> 39 <td align="center"><%=rs.getObject(1) %></td> 40 <td align="center"><%=rs.getObject(2) %></td> 41 <td align="center"><%=rs.getObject(3) %></td> 42 <td align="center"><%=rs.getObject(4) %></td> 43 <td align="center"><%=rs.getObject(5) %></td> 44 <td align="center"><%=rs.getObject(6) %></td> 45 <td align="center"><%=rs.getObject(7) %></td> 46 <td align="center"><%=rs.getObject(8) %></td> 47 </tr> 48 <% 49 } 50 } 51 } catch (SQLException e) { 52 e.printStackTrace(); 53 }finally{ 54 util.close(rs); 55 util.close(preparedStatement); 56 util.close(connection); 57 } 58 %> 59 </table> 60 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 61 <input type="button" name="back" onclick="javascript:window.history.back(-1);" value=返回上一页> 62 <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 63 </p> 64 </body> 65 </html>
15.show.jsp
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>浏览信息</title> 8 </head> 9 <body> 10 11 <jsp:useBean id="util" class="test.Data" scope="page" /> 12 <table border="1"style="text-align:center;"> 13 <tr> 14 <td align="center" width=6%>活动主题</td> 15 <td align="center" width=8%>活动目的</td> 16 <td align="center" width=10%>活动类型</td> 17 <td align="center" width=10%>活动时间</td> 18 <td align="center" width=6%>活动地点</td> 19 <td align="center" width=18%>活动对象</td> 20 <td align="center" width=3%>活动内容</td> 21 <td align="center" width=10>活动日程安排</td> 22 </tr> 23 <% 24 Connection connection = util.getConnection(); 25 PreparedStatement preparedStatement=null; 26 ResultSet rs=null; 27 try { 28 String sql = "select * from active"; 29 preparedStatement=connection.prepareStatement(sql); 30 rs=preparedStatement.executeQuery(); 31 while(rs.next()){ 32 %> 33 <tr> 34 <td align="center"><%=rs.getObject(1) %></td> 35 <td align="center"><%=rs.getObject(2) %></td> 36 <td align="center"><%=rs.getObject(3) %></td> 37 <td align="center"><%=rs.getObject(4) %></td> 38 <td align="center"><%=rs.getObject(5) %></td> 39 <td align="center"><%=rs.getObject(6) %></td> 40 <td align="center"><%=rs.getObject(7) %></td> 41 <td align="center"><%=rs.getObject(8) %></td> 42 </tr> 43 <% 44 } 45 } catch (SQLException e) { 46 e.printStackTrace(); 47 }finally{ 48 util.close(rs); 49 util.close(preparedStatement); 50 util.close(connection); 51 } 52 %> 53 </table> 54 <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 55 <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> 56 </p> 57 </body> 58 </html>
在本次的期中考试中,我基本完成了系统所需要求,但是系统仍有很大缺陷,例如虽然做了活动若有多项重复内容时不可录入的判断操作,但如果录入多个主题相同但内容,时间地点等不同的活动后在进行删除操作时会删除所有主题相同活动,对于这一点,我会在往后的学习中积极加以改进。
标签:总结,preparedStatement,String,期中考试,active,close,活动,public From: https://www.cnblogs.com/sgle0722/p/16849121.html