石家庄铁道大学2022年秋季2021级Java期中考试--校园社团活动管理系统(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分。)
Navicat:
打开心爱的idea:
Bean1:
package com.Bean;
public class Bean1 {
String theme,purpose,kind,time,place,object,content,arrange;
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public String getPurpose() {
return purpose;
}
public void setPurpose(String purpose) {
this.purpose = purpose;
}
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
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 getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getArrange() {
return arrange;
}
public void setArrange(String arrange) {
this.arrange = arrange;
}
}
Dao1:
package com.Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.Bean.Bean1;
import com.Util.Util1;
import com.mysql.cj.Session;
/*
* 使用数据库进行增删改查
* */
public class Dao1 {
/*
* 增
* */
public int add(Bean1 claz) throws ClassNotFoundException, SQLException {
//获得链接对象
Connection connection = Util1.getConnection();
//准备sql语句
String sql = "insert into biao2(theme,purpose,kind,time,place,object,content,arrange) values(?,?,?,?,?,?,?,?)";
PreparedStatement preparedStatement = null;
try {
//创建语句传输对象
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, claz.getTheme());
preparedStatement.setString(2, claz.getPurpose());
preparedStatement.setString(3, claz.getKind());
preparedStatement.setString(4, claz.getTime());
preparedStatement.setString(5, claz.getPlace());
preparedStatement.setString(6, claz.getObject());
preparedStatement.setString(7, claz.getContent());
preparedStatement.setString(8, claz.getArrange());
preparedStatement.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
//关闭资源
Util1.close(preparedStatement);
Util1.close(connection);
}
return 1;
}
/*
* 删
* */
public int delete(String theme) throws SQLException, ClassNotFoundException {
Connection conn = Util1.getConnection();
String sql = "delete from biao2 where theme=?";
PreparedStatement pstmt = null;
int i=0;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,theme);
i = pstmt.executeUpdate(); //执行sql
System.out.println("result: " + i);
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
//关闭资源
Util1.close(pstmt);
Util1.close(conn);
} return i;
}
/*
* 改
* */
public int revise(Bean1 claz) throws SQLException, ClassNotFoundException {
System.out.println("-----------revise--------------");
Connection conn = Util1.getConnection();
int i = 0;
PreparedStatement pstmt = null;
try {
String sql = "update biao2 set purpose=? , kind=? , time=? , place=? , object=? , content=? , arrange=? where theme= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, claz.getPurpose());
pstmt.setString(2, claz.getKind());
pstmt.setString(3, claz.getTime());
pstmt.setString(4, claz.getPlace());
pstmt.setString(5, claz.getObject());
pstmt.setString(6, claz.getContent());
pstmt.setString(7, claz.getArrange());
pstmt.setString(8, claz.getTheme());
i = pstmt.executeUpdate();
// System.out.println("result: " + i);
// pstmt.close();
// conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
//关闭资源
Util1.close(pstmt);
Util1.close(conn);
return i;
}
}
/*
* 查所有
* */
public List<Bean1> selectall()throws Exception {
Connection conn = Util1.getConnection();
String sql = "select * from biao2";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
List<Bean1> clazs=new ArrayList<>();
while(rs.next()){
//获取数据
String theme = rs.getString("theme");
String purpose = rs.getString("purpose");
String kind = rs.getString("kind");
String time = rs.getString("time");
String place = rs.getString("place");
String object = rs.getString("object");
String content = rs.getString("content");
String arrange = rs.getString("arrange");
//封装Brand对象
Bean1 claz=new Bean1();
claz.setTheme(theme);
claz.setPurpose(purpose);
claz.setKind(kind);
claz.setTime(time);
claz.setPlace(place);
claz.setObject(object);
claz.setContent(content);
claz.setArrange(arrange);
//装载集合
clazs.add(claz);
}
// System.out.println(clazs);
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
//关闭资源
Util1.close(pstmt);
Util1.close(conn);
}
return null;
}
/*
* 查单个
* */
public int selecteach(String theme)throws Exception {
Connection conn = Util1.getConnection();
String sql = "select * from biao2 where theme=?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,theme);
ResultSet rs = pstmt.executeQuery();
int col=rs.getMetaData().getColumnCount();
System.out.println("====================================");
while(rs.next()){
for(int i=1;i<=col;i++){
System.out.println(rs.getString(i)+"\t");
System.out.println("\t");
}
}
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
//关闭资源
Util1.close(pstmt);
Util1.close(conn);
}
return 1;
}
}
Util1:
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;
/*
* 连接数据库
* */
public class Util1 {
public static Connection getConnection() throws ClassNotFoundException, SQLException {
Connection connection = null;//连接数据库
PreparedStatement pstmt = null;//Statement 对象用于将 SQL 语句发送到数据库中。Statement stmt = connection.createStatement();
ResultSet rs = null;
//1. 导入驱动jar包
//2.注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/xingcheng?useUnicode=true&characterEncoding=utf8", "root", "xlm178413954");
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();
}
}
public static void main(String[] args) {
}
}
add.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 14:21
To change this template use File | Settings | File Templates.
--%>
<%@ 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">
<head>
<meta charset="UTF-8" >
<title>发布活动信息</title>
</head>
<body>
<form action="addback.jsp" method="post">
<table align="center" border="1" width="500">
<tr>
<td>1.活动主题 </td>
<td>
<label>
<input type="text" name="theme" maxlength="20" />
</label>
</td>
</tr>
<tr>
<td>2.活动目的 </td>
<td>
<label>
<input type="text" name="purpose" maxlength="50"/>
</label>
</td>
</tr>
<tr>
<td>3.活动类型 </td>
<td>
<label>
<select name="kind">
<option value="社团竞赛"selected>社团竞赛</option>
<option value="野外采风">野外采风</option>
<option value="校内集会">校内集会</option>
<option value="社团纳新">社团纳新</option>
</select>
</label>
</td>
</tr>
<tr>
<td>4.活动时间 </td>
<td>
<label>
<input type="text" name="time"/>
</label>
</td>
</tr>
<tr>
<td>5.活动地点 </td>
<td>
<label>
<input type="text" name="place"/>
</label>
</td>
</tr>
<tr>
<td>6.活动对象 </td>
<td>
<label>
<input type="checkbox" name="a1" value="社团成员," checked="checked"/>社团成员
<input type="checkbox" name="a2" value="全体学生" />全体学生
</label>
</td>
</tr>
<tr>
<td>7.活动内容 </td>
<td>
<label>
<input type="text" name="content" maxlength="500" />
</label>
</td>
</tr>
<tr>
<td>8.活动日程安排 </td>
<td>
<label>
<input type="text" name="arrange" maxlength="500"/>
</label>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="发布" />
<input type="reset" value="刷新" />
</td>
</tr>
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'"/>
</table>
</form>
</body>
addback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 14:34
To change this template use File | Settings | File Templates.
--%>
<%@page import="com.Bean.Bean1"%>
<%@page import="com.Dao.Dao1"%>
<%@ page import="java.sql.SQLException" %>
<%@ 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>
<title>发布活动结果</title>
<meta charset="UTF-8">
<%
request.setCharacterEncoding("UTF8"); //老重要了,没有这个语句,数据库里的中文全显示乱码
int i=0;
String theme = request.getParameter("theme");
String purpose = request.getParameter("purpose");
String kind = request.getParameter("kind");
String time = request.getParameter("time");
String place = request.getParameter("place");
String content = request.getParameter("content");
String arrange = request.getParameter("arrange");
String a1=null;
String a2=null;
if(request.getParameter("a1")!=null)
{
a1=request.getParameter("a1");
}
else a1="";
if(request.getParameter("a2")!=null)
{
a2=request.getParameter("a2");
}
else a2="";
String object=a1+a2;
Bean1 bean = new Bean1();
bean.setTheme(theme);
bean.setPurpose(purpose);
bean.setKind(kind);
bean.setTime(time);
bean.setPlace(place);
bean.setContent(content);
bean.setArrange(arrange);
bean.setObject(object);
Dao1 dao =new Dao1();
try {
i=dao.add(bean);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
if(i==1) {
response.getWriter().append("填报成功!");
session.setAttribute("theme", theme);
session.setAttribute("purpose", purpose);
session.setAttribute("kind", kind);
session.setAttribute("time", time);
session.setAttribute("place", place);
session.setAttribute("object",object);
session.setAttribute("content",content);
session.setAttribute("arrange",arrange);
response.sendRedirect("addbackback.jsp");
}
// response.sendRedirect("show.jsp");
else {
response.getWriter().append("信息填报系统发生错误!请重新填写");
response.sendRedirect("add.jsp");
}
%>
</html>
<%!
%>
addbackback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:08
To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="com.Util.Util1" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>添加结果显示</title>
</head>
<body>
<%
String theme=(String) session.getAttribute("theme");
String purpose=(String)session.getAttribute("purpose");
String kind=(String)session.getAttribute("kind");
String time=(String)session.getAttribute("time");
String place=(String)session.getAttribute("place");
String object=(String)session.getAttribute("object");
String content=(String)session.getAttribute("content");
String arrange=(String)session.getAttribute("arrange");
if(time==""||theme==""||kind==""||place==""||object==""||content==""||arrange=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else
{
%>
<table border="1" cellspacing="0">
<tr>
<td align="center" width=20%>活动主题</td>
<td align="center" width=10%>活动目的</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=6%>活动地点</td>
<td align="center" width=10%>活动对象</td>
<td align="center" width=50%>活动内容</td>
<td align="center" width=30%>活动日程安排</td>
</tr>
<tr>
<td align="center"><%=theme %></td>
<td align="center"><%=purpose %></td>
<td align="center"><%=kind %></td>
<td align="center"><%=time %></td>
<td align="center"><%=place %></td>
<td align="center"><%=object%></td>
<td align="center"><%=content %></td>
<td align="center"><%=arrange %></td>
</tr>
<%}%>
</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>
delete.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 14:48
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
<title>删除行程</title>
</head>
<body>
<h3>行程删除</h3>
<form action="deleteback.jsp" method="post">
<p style="text-align:center;color:black;font-family:宋体;font-size:20px">
<br>
<tr>要删除的活动的主题:<input type="text" name="theme" /></tr>
<br>
<input type="submit" value="删除" />
<input type="reset" value="刷新"/>
<br>
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'"/>
</p>
</form>
</body>
</html>
deleteback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:32
To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.Bean.Bean1" %>
<%@ page import="com.Dao.Dao1" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>删除活动信息结果</title>
</head>
<body>
<table>
<%
request.setCharacterEncoding("UTF8"); //老重要了,没有这个语句,数据库里的中文全显示乱码
int i=0;
String theme= request.getParameter("theme");
if(theme==""){
out.print("<script language='javaScript'>alert('输入为空');window.history.back(-1);</script>");
}else {
Dao1 dao = new Dao1();
try {
i = dao.delete(theme);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
if (i!=0){
response.getWriter().append("删除成功!");
// response.sendRedirect("show.jsp");
}
else {
response.getWriter().append("删除失败,请重新填写");
response.sendRedirect("delete.jsp");
}
}
%>
</table>
<p>
<br>
<input type="button" value="主页面" onclick="location.href='menu.jsp'" />
</p>
</body>
</html>
menu.jsp
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 14:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>主菜单</title>
</head>
<body>
<input type="button" value="发布活动信息" onclick="location.href='add.jsp'"/>
<input type="button" value="删除活动信息" onclick="location.href='delete.jsp'"/>
<input type="button" value="修改活动信息" onclick="location.href='revise.jsp'"/>
<input type="button" value="查询活动信息" onclick="location.href='search.jsp'"/>
<input type="button" value="活动信息浏览" onclick="location.href='show.jsp'"/>
</body>
</html>
revise.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:13
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改活动信息</title>
</head>
<body>
<form action="reviseback.jsp" method="get">
<p>
<h3>修改</h3>
<p style="text-align:center;color:black;font-family:宋体;font-size:20px">
<table align="center" border="1" width="500">
<tr>
<td>要修改的主题 </td>
<td>
<label>
<input type="text" name="theme" />
</label>
</td>
</tr>
<tr>
</table>
<input type="submit" value="提交" />
<input type="reset" value="刷新"/>
<br>
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'"/>
</p>
</form>
</p>
</body>
</html>
revise1.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 16:36
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.Util1" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>要修改的信息显示</title>
</head>
<body>
<%
String theme=request.getParameter("theme");
if(theme=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else{
%>
<table border="1" cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=20%>活动主题</td>
<td align="center" width=10%>活动目的</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=6%>活动地点</td>
<td align="center" width=10%>活动对象</td>
<td align="center" width=50%>活动内容</td>
<td align="center" width=30%>活动日程安排</td>
</tr>
<%
int i=0;
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from biao2 where theme=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,theme);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(theme.equals(rs.getObject(1)))
{
i++;
%>
<tr>
<td align="center"><a style="color:blue" href='reviseback.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a></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{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.close(connection);
}
%>
</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>
reviseback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:14
To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Dao.Dao1" %>
<%@ page import="com.Bean.Bean1" %>
<%@ page import="com.Util.Util1" %>
<%
String theme=request.getParameter("theme");
session.setAttribute("theme",theme);
%>
<html>
<head>
<title>修改活动信息</title>
</head>
<body>
<form action="revisebackback.jsp" method="post">
<%
if(theme=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else{
%>
<table border="1" cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=20%>活动主题</td>
<td align="center" width=10%>活动目的</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=6%>活动地点</td>
<td align="center" width=10%>活动对象</td>
<td align="center" width=50%>活动内容</td>
<td align="center" width=30%>活动日程安排</td>
</tr>
<%
int i=0;
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from biao2 where theme=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,theme);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(theme.equals(rs.getObject(1)))
{
i++;
%>
<tr>
<td align="center"><a href='reviseback.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(1) %></a></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{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.close(connection);
}
%>
</table>
<%
}
%>
<table>
<h1>修改活动信息</h1>
<tr>
<tr>填写要修改的信息</tr>
<br>
<br>
<tr>
<td>2.活动目的 </td>
<td>
<label>
<input type="text" name="purpose" maxlength="50"/>
</label>
</td>
</tr>
<tr>
<td>3.活动类型 </td>
<td>
<label>
<select name="kind">
<option value="社团竞赛"selected>社团竞赛</option>
<option value="野外采风">野外采风</option>
<option value="校内集会">校内集会</option>
<option value="社团纳新">社团纳新</option>
</select>
</label>
</td>
</tr>
<tr>
<td>4.活动时间 </td>
<td>
<label>
<input type="text" name="time"/>
</label>
</td>
</tr>
<tr>
<td>5.活动地点 </td>
<td>
<label>
<input type="text" name="place"/>
</label>
</td>
</tr>
<tr>
<td>6.活动对象 </td>
<td>
<label>
<input type="checkbox" name="a1" value="社团成员," checked="checked"/>社团成员
<input type="checkbox" name="a2" value="全体学生" />全体学生
</label>
</td>
</tr>
<tr>
<td>7.活动内容 </td>
<td>
<label>
<input type="text" name="content" maxlength="500" />
</label>
</td>
</tr>
<tr>
<td>8.活动日程安排 </td>
<td>
<label>
<input type="text" name="arrange" maxlength="500"/>
</label>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="修改" />
<input type="reset" value="刷新" />
</td>
</tr>
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'"/>
</table>
</form>
</body>
</html>
revisebackback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:20
To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.Bean.Bean1" %>
<%@ page import="com.Dao.Dao1" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改行程信息结果</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF8"); //老重要了,没有这个语句,数据库里的中文全显示乱码
int i=0;
String theme =(String)session.getAttribute("theme");
String purpose = request.getParameter("purpose");
String kind = request.getParameter("kind");
String time = request.getParameter("time");
String place = request.getParameter("place");
String content = request.getParameter("content");
String arrange = request.getParameter("arrange");
String a1=null;
String a2=null;
if(request.getParameter("a1")!=null)
{
a1=request.getParameter("a1");
}
else a1="";
if(request.getParameter("a2")!=null)
{
a2=request.getParameter("a2");
}
else a2="";
String object=a1+a2;
Bean1 bean = new Bean1();
bean.setTheme(theme);
bean.setPurpose(purpose);
bean.setKind(kind);
bean.setTime(time);
bean.setPlace(place);
bean.setContent(content);
bean.setArrange(arrange);
bean.setObject(object);
Dao1 dao =new Dao1();
try {
i = dao.revise(bean);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
if (i != 0) {
response.getWriter().append("修改成功!");
response.setHeader("refresh","0;url=revise.jsp");
}
else {
response.getWriter().append("修改失败,请重新填写");
response.sendRedirect("reviseback.jsp");
}
%>
</body>
</html>
search.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:47
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>查询</title>
</head>
<body>
<form action="searchback.jsp" method="get">
输入要查询的活动的主题/时间/地点/类型 (支持模糊查询)
<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>
</form>
</body>
</html>
searchall.jsp:
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.Util1" %>
<!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=20%>活动主题</td>
<td align="center" width=10%>活动目的</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=6%>活动地点</td>
<td align="center" width=10%>活动对象</td>
<td align="center" width=50%>活动内容</td>
<td align="center" width=30%>活动日程安排</td>
</tr>
<%
String id=request.getParameter("id");
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from biao2";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(id.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{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.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>
searchback.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 15:50
To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="com.Util.Util1" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>查询基本结果</title>
</head>
<body>
<%
String data=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=20%>活动主题</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=10%>活动对象</td>
</tr>
<%
int i=0;
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql= " select * from biao2 where theme like ? or kind like ? or time like ? or object 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='searchall.jsp?id=<%=rs.getObject(1)%>'><%=rs.getObject(1) %></a></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
</tr>
<%
}
if(i==0)
{
out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.close(connection);
}
}
%>
</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>
show.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 14:56
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.Util1" %>
<!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=20%>活动主题</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=10%>活动对象</td>
</tr>
<%
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from biao2";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
%>
<tr>
<td align="center"><a href='showall.jsp?id=<%=rs.getObject(1)%>'><%=rs.getObject(1)%></a></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
</tr>
<%
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.close(connection);
}
%>
</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>
showall.jsp:
<%--
Created by IntelliJ IDEA.
User: xielumeng
Date: 2022/10/28
Time: 16:18
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.Util1" %>
<!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=20%>活动主题</td>
<td align="center" width=10%>活动目的</td>
<td align="center" width=4%>活动类型</td>
<td align="center" width=10%>活动时间</td>
<td align="center" width=6%>活动地点</td>
<td align="center" width=10%>活动对象</td>
<td align="center" width=50%>活动内容</td>
<td align="center" width=30%>活动日程安排</td>
</tr>
<%
String id=request.getParameter("id");
Connection connection = Util1.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from biao2";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(id.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"><%=rs.getObject(9) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
Util1.close(rs);
Util1.close(preparedStatement);
Util1.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>