校园社团活动管理系统(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分。)
sqll.java
package Bean; import java.sql.*; public class sqll { public static Connection getConnection() throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/jianmin", "root", ""); return c; } }
Data.java
package test; import Bean.sqll; import java.sql.*; import java.util.regex.Pattern; public class Data { private String zhuti, mudi, leixing, shijian, didian, duixiang, neirong, anpai; public String getZhuti() { return zhuti; } public String getMudi() { return mudi; } public String getLeixing() { return leixing; } public String getShijian() { return shijian; } public String getDidian() { return didian; } public String getDuixiang() { return duixiang; } public String getNeirong() { return neirong; } public String getAnpai() { return anpai; } public void setZhuti(String zhuti) { this.zhuti = zhuti; } public void setMudi(String mudi) { this.mudi = mudi; } public void setLeixing(String leixing) { this.leixing = leixing; } public void setShijian(String shijian) { this.shijian = shijian; } public void setDidian(String didian) { this.didian = didian; } public void setDuixiang(String duixiang) { this.duixiang = duixiang; } public void setNeirong(String neirong) { this.neirong = neirong; } public void setAnpai(String anpai) { this.anpai = anpai; } public static void main(String[] args) { } public void adddata(String zhuti, String mudi, String leixing, String shijian, String didian, String duixiang, String neirong, String anpai) throws Exception { Connection connection = sqll.getConnection(); PreparedStatement preparedStatement = null; String sql = "insert into t0 (zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai) values (?,?,?,?,?,?,?,?)"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, zhuti); preparedStatement.setString(2, mudi); preparedStatement.setString(3, leixing); preparedStatement.setString(4, shijian); preparedStatement.setString(5, didian); preparedStatement.setString(6, duixiang); preparedStatement.setString(7, neirong); preparedStatement.setString(8, anpai); preparedStatement.executeUpdate(); } // 删 public void deletedata(String zhuti) throws Exception { Connection connection = sqll.getConnection(); PreparedStatement preparedStatement = null; String sql = "delete from t0 where zhuti = ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, zhuti); preparedStatement.executeUpdate(); } // 改 public void revisedata(String id0, String mudi, String leixing, String shijian, String didian, String duixiang, String neirong, String anpai) throws Exception { Connection connection = sqll.getConnection(); PreparedStatement preparedStatement = null; String sql = "update t0 set mudi=?, leixing=?, shijian=?, didian=?, duixiang=?, neirong=?, anpai=? where zhuti=?"; 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, id0); preparedStatement.executeUpdate(); } // 判重/判存在 public boolean isSame(String s) throws Exception { Connection connection = sqll.getConnection(); PreparedStatement preparedStatement = null; ResultSet rs = null; String sql = "select * from t0"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); while (rs.next()) { if (s.equals(rs.getObject(1))) return true; } return false; } }
menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-主菜单</title> </head> <body background="0.jpg"> <form> <p style="text-align:center"> 活动普查系统 <br><input type="button" value="发布活动信息" onclick="location.href='add.jsp'" /> <input type="button" value="修改活动信息" onclick="location.href='revise.jsp'" /> <input type="button" value="删除活动信息" onclick="location.href='delete.jsp'" /> <input type="button" value="查询活动信息" onclick="location.href='search.jsp'" /> <input type="button" value="活动信息浏览" onclick="location.href='show.jsp'" /> <br> </p> </form> </body> </html>
add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-添加</title> </head> <body background="3.jpg"> <form action="addjudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 添加活动信息 <br> <br> <br> 活动主题 <input type="text" name="zhuti" size="20"/><br> <br> 活动目的 <input type="text" name="mudi" size="20"/><br> <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> <br> 活动时间 <input type="text" name="shijian" size="20"/><br> <br> 活动地点 <input type="text" name="didian" size="20"/><br> <br>行程统计:<input type="checkbox" name="duixiang1" value="社团成员">社团成员 <input type="checkbox" name="duixiang2" value="全体学生">全体学生<br> <br> 活动内容 <input type="text" name="neirong" size="50"/><br> <br> 活动日程安排 <input type="text" name="anpai" size="50"/><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>
addjudge.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-添加1</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% //hubie,housetype,houseS,home,name,id,sex,minzu,edu; String zhuti=(String)request.getParameter("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 = ""; if((request.getParameter("duixiang1")!=null)&&(request.getParameter("duixiang2")!=null)){ duixiang+=request.getParameter("duixiang1"); duixiang+="和"; duixiang+=request.getParameter("duixiang2"); } else if(request.getParameter("duixiang1")!=null) duixiang+=request.getParameter("duixiang1"); else if(request.getParameter("duixiang2")!=null) duixiang+=request.getParameter("duixiang2"); String neirong=(String)request.getParameter("neirong"); String anpai=(String)request.getParameter("anpai"); if(util.isSame(zhuti)) { out.print("<script language='javaScript'> alert('活动主题重复'); window.history.back(-1); </script>"); } else if(zhuti.length()>20){ out.print("<script language='javaScript'> alert('活动主题过长');window.history.back(-1);</script>"); } else if(mudi.length()>50){ out.print("<script language='javaScript'> alert('活动目的过长');window.history.back(-1);</script>"); } else if(neirong.length()>500){ out.print("<script language='javaScript'> alert('活动内容过长');window.history.back(-1);</script>"); } else if(anpai.length()>500){ out.print("<script language='javaScript'> alert('活动日程安排过长');window.history.back(-1);</script>"); } else{ util.adddata(zhuti, mudi, leixing, shijian, didian, duixiang, neirong, anpai); out.print("<script language='javaScript'> alert('添加成功');</script>"); response.setHeader("refresh", "0;url=show2.jsp"); } %> </body> </html>
delete.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-删除</title> </head> <body background="3.jpg"> <form action="deletejudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 删除活动信息页面 <br> 要删除信息的活动主题: <input type="text" name="zhuti" /> <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>
deletejudge.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民测测试-删除1</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String zhuti=(String)request.getParameter("zhuti"); if(zhuti==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else if(!util.isSame(zhuti)) { out.print("<script language='javaScript'> alert('不存在'); window.history.back(-1); </script>"); } else{ %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=8%>活动目的</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=6%>活动地点</td> <td align="center" width=18%>活动对象</td> <td align="center" width=8%>活动内容</td> <td align="center" width=15>活动日程安排</td> <td align="center" width=3%>删除</td> </tr> <% Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(zhuti.equals(rs.getObject(1))) { %> <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> <td align="center"><a style="color:blue" href='deletejudge2.jsp?id=<%=rs.getObject(1) %>' onclick="javascript:return del()">删除</a> </td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ } %> </table> <% } %> <script> function del(){ var r = confirm("确定要删除吗?") if (r == true) { return true; } else { return false; } } </script> <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>
deletejudge2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-删除2</title> </head> <body background="3.jpg"> <!-- <input type="button" onclick="openResult()" value="删除"/> --> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String zhuti=(String)request.getParameter("zhuti"); util.deletedata(zhuti); out.print("<script language='javaScript'> alert('删除成功');</script>"); response.setHeader("refresh", "0;url=delete.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>
revise.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-修改</title> </head> <body background="3.jpg"> <form action="revisejudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> 输入要修改的活动主题 <input type="text" name="zhuti" /><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>
revisejudge.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-修改-1</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String zhuti=(String)request.getParameter("zhuti"); if(zhuti==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else if(!util.isSame(zhuti)) { out.print("<script language='javaScript'> alert('该活动不存在'); window.history.back(-1); </script>"); } else{ %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=8%>活动目的</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=6%>活动地点</td> <td align="center" width=18%>活动对象</td> <td align="center" width=8%>活动内容</td> <td align="center" width=15>活动日程安排</td> <td align="center" width=3%>修改</td> </tr> <% Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(zhuti.equals(rs.getObject(1))) { %> <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> <td align="center"><a style="color:blue" href='revisejudge2.jsp?id0=<%=rs.getObject(1) %>'>修改</a> </td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ } %> </table> <% } %> <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>
revisejudge2.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-修改-2</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id0=(String)request.getParameter("id0"); session.setAttribute("id0",id0); %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=8%>活动目的</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=6%>活动地点</td> <td align="center" width=18%>活动对象</td> <td align="center" width=8%>活动内容</td> <td align="center" width=15>活动日程安排</td> </tr> <% Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(id0.equals(rs.getObject(1))) { %> <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{ } %> </table> <form action="revisejudge3.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <br> 修改信息 <br> 活动目的 <input type="text" name="mudi" size="20"/><br> <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> <br> 活动时间 <input type="text" name="shijian" size="20"/><br> <br> 活动地点 <input type="text" name="didian" size="20"/><br> <br>行程统计:<input type="checkbox" name="duixiang1" value="社团成员.">社团成员 <input type="checkbox" name="duixiang2" value="全体学生.">全体学生<br> <br> 活动内容 <input type="text" name="neirong" size="50"/><br> <br> 活动日程安排 <input type="text" name="anpai" size="50"/><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>
revisejudge3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-修改-3</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id0=(String)session.getAttribute("id0"); 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 = ""; if(request.getParameter("duixiang1")!=null) duixiang+=request.getParameter("duixiang1"); if(request.getParameter("duixiang2")!=null) duixiang+=request.getParameter("duixiang2"); String neirong=(String)request.getParameter("neirong"); String anpai=(String)request.getParameter("anpai"); if(mudi==""||leixing==""||shijian==""||didian==""||duixiang==""||neirong==""||anpai=="") { out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); } else if(mudi.length()>20){ out.print("<script language='javaScript'> alert('活动目的过长');window.history.back(-1);</script>"); } else if(neirong.length()>500){ out.print("<script language='javaScript'> alert('活动内容过长');window.history.back(-1);</script>"); } else if(anpai.length()>20){ out.print("<script language='javaScript'> alert('活动日程安排过长');window.history.back(-1);</script>"); } else { util.revisedata(id0,mudi,leixing,shijian,didian,duixiang,neirong,anpai); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=revise.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>
search.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-查询</title> </head> <body background="3.jpg"> <form action="searchjudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 输入要查询信息的活动主题、活动时间、活动类型、活动地点(支持模糊查询): <br> <input type="text" name="data" /> <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>
searchjudge.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-查询后台</title> </head> <body background="3.jpg" style="text-align:center"> 查询结果 <p> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String data=(String)request.getParameter("data"); if(data==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else { %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=18%>活动对象</td> </tr> <% int i=0; Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql= " select * from t0 where zhuti like ? or shijian like ? or leixing like ? or didian 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 style="color:blue" href='searchshowall.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a> </td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></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{ } } %> </table> <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>
searchshowall.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-查询显示详细信息</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id = (String)request.getParameter("id"); Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(id.equals(rs.getObject(1))) { %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=8%>活动目的</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=6%>活动地点</td> <td align="center" width=18%>活动对象</td> <td align="center" width=8%>活动内容</td> <td align="center" width=15>活动日程安排</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{ } %> </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>
show.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-浏览</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=18%>活动对象</td> </tr> <% Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ %> <tr > <td align="center"><a style="color:blue" href='searchshowall.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a> </td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(6) %></td> </tr> <% } } catch (SQLException e) { e.printStackTrace(); }finally{ } %> </table> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
show2.jsp
<%@page import="Bean.sqll"%> <%@ page import="java.sql.*" %><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>建民的测试-浏览</title> </head> <body background="3.jpg"> <jsp:useBean id="util" class="test.Data" scope="page" /> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>活动主题</td> <td align="center" width=10%>活动类型</td> <td align="center" width=10%>活动时间</td> <td align="center" width=18%>活动对象</td> </tr> <% String str=""; Connection connection = sqll.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); rs.last(); str=(String)rs.getObject(1); %> <tr style="color:red"> <td align="center"><a style="color:blue" href='searchshowall.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a> </td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(6) %></td> </tr> <% } catch (SQLException e) { e.printStackTrace(); }finally{ } %> <% connection = sqll.getConnection(); preparedStatement=null; rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ String str2=(String)rs.getObject(1); if(str.equals(str2)) break; %> <tr > <td align="center"><a style="color:blue" href='searchshowall.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a> </td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(6) %></td> </tr> <% } } catch (SQLException e) { e.printStackTrace(); }finally{ } %> </table> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
部分有点问题
参考:https://www.cnblogs.com/a8047/p/13991772.html
标签:王建民,JAVA,String,29,alert,preparedStatement,jsp,活动,public From: https://www.cnblogs.com/zhangxutong/p/16838416.html