校园社团活动管理系统(20分) --期中考试

考试题目要求实现一个校园社团管理系统

整体框架

sql操作工具类
 package tool;
import java.sql.*;
public class Mysqltool {
	private static Connection con;
	private static PreparedStatement psta;
	private static ResultSet res;
	public static Connection getcon() {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			String url="jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=utf-8";
			con=DriverManager.getConnection(url,"root","111111");
			return con;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static ResultSet executequ(Connection Con,String sql,Object[] s) throws SQLException {
		psta=Con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
		for(int i=0;i<s.length;i++) {
			psta.setObject(i+1, s[i]);
		}
		res=psta.executeQuery();
		return res;
	}
	public static ResultSet executequ(Connection Con,String sql) throws SQLException {
		psta=Con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
		res=psta.executeQuery();
		return res;
	}
	public static int executeup(Connection Con,String sql,Object[] s) throws SQLException {
		psta=Con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
		for(int i=0;i<s.length;i++) {
			psta.setObject(i+1, s[i]);
		}
		int row=psta.executeUpdate();
		return row;
	}
	public static int executeup(Connection Con,String sql) throws SQLException {
		psta=Con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
		int row=psta.executeUpdate();
		return row;
	}
	public static void Close() {
		try {
			if(con!=null)
			con.close();
			if(res!=null)
			res.close();
			if(psta!=null)
			psta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
主界面
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>主页面</title>
</head>
<body>
<a href="publish.html">发动活动信息</a>
<a href="revise.html">修改活动信息</a>
<a href="delete.html">删除活动信息</a>
<a href="browse.jsp">浏览活动信息</a>
<a href="inquire.html">查询活动信息</a>
</body>
</html>
发布
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>发布活动信息页面</title>
</head>
<body>
<form action="publish.jsp" method="post">
<h3>活动主题</h3>
<p><input type="text" name="theme" onblur="if(!/[\u4e00-\u9fa5]/.test(this.value)||this.value.length>20){value='';alert('请输入长度不超过20个中文');}"></p>
<h3>活动目的</h3>
<p><input type="text" name="aim"  onblur="if(!/[\u4e00-\u9fa5]/.test(this.value)||this.value.length>50){value='';alert('请输入长度不超过50个中文');}"></p>
<h3>活动类型</h3>
<p><input type="radio" name="kind" value="社团竞赛">社团竞赛</p>
<p><input type="radio" name="kind" value="野外采风">野外采风</p>
<p><input type="radio" name="kind" value="校内集会">校内集会</p>
<p><input type="radio" name="kind" value="社团纳新">社团纳新</p>
<h3>活动时间</h3>
<p><input type="text" name="time"></p>
<h3>活动地点</h3>
<p><input type="text" name="place"></p>
<h3>活动对象</h3>
<p><input type="checkbox" name="people1" value="社团成员">社团成员</p>
<p><input type="checkbox" name="people2" value="全体学生">全体学生</p>
<h3>活动内容</h3>
<p><input type="text" name="content" onblur="if(!/[\u4e00-\u9fa5]/.test(this.value)||this.value.length>500){value='';alert('请输入长度不超过500个中文');}"></p>
<h3>活动日程安排</h3>
<p><input type="text" name="plan" onblur="if(!/[\u4e00-\u9fa5]/.test(this.value)||this.value.length>500){value='';alert('请输入长度不超过500个中文');}"></p>
<p><input type="submit" value="提交"></p>
</form>
</body>
</html>
发布
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="java.sql.ResultSet"%>
<%@page import="tool.Mysqltool"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>发布活动信息结果页面</title>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
	String[] s=new String[8];
	s[0]=request.getParameter("theme");
	s[1]=request.getParameter("aim");
	s[2]=request.getParameter("kind");
	s[3]=request.getParameter("time");
	s[4]=request.getParameter("place");
	StringBuilder str=new StringBuilder();
	if(request.getParameter("people1")!=null)
	str.append(request.getParameter("people1"));
	System.out.print(request.getParameter("people1")+" "+request.getParameter("people2"));
	if(request.getParameter("people2")!=null)
    str.append(" "+request.getParameter("people2"));
	s[5]=str.toString();
	System.out.print(s[5]);
	s[6]=request.getParameter("content");
	s[7]=request.getParameter("plan");
	String sql="insert into `activity` values(?,?,?,?,?,?,?,?)";
	int row=Mysqltool.executeup(Mysqltool.getcon(), sql, s);
	if(row<1){
		Mysqltool.Close();
%>
<script type="text/javascript">
window.alert('提交失败');
location.assign("publish.html");
</script>
<%
	}
	else{
		ServletContext con=this.getServletContext();
		con.setAttribute("theme", s[0]);
		Mysqltool.Close();
%>
<script type="text/javascript">
window.alert('提交成功');
location.assign("browse.jsp");
</script>
<%
	}
	
%>
</body>
</html>
修改
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改活动信息页面</title>
</head>
<body>
<form action="revise.jsp" method="post">
<p><input type="text" name="theme"></p>
<p><input type="submit" value="查询"></p>
</form>
</body>
</html>
修改
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改活动信息页面</title>
</head>
<body>
<form action="revise.jsp" method="post">
<p><input type="text" name="theme"></p>
<p><input type="submit" value="查询"></p>
</form>
</body>
</html>
修改
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="tool.Mysqltool"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改信息页面</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String[] s=new String[8];
ServletContext con=this.getServletContext();
s[7]=(String)con.getAttribute("theme");
s[0]=request.getParameter("aim");
s[1]=request.getParameter("kind");
s[2]=request.getParameter("time");
s[3]=request.getParameter("place");
s[4]=request.getParameter("people");
s[5]=request.getParameter("content");
s[6]=request.getParameter("plan");
String sql="update `activity` set  `目的`=?,`类型`=?,`时间`=?,`地点`=?,`对象`=?,`内容`=?,`日程安排`=? where `主题`=?";
Mysqltool.executeup(Mysqltool.getcon(), sql, s);
Mysqltool.Close();
%>
<script type="text/javascript">
alert('修改成功')
</script>
</body>
</html>
删除
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除活动信息页面</title>
</head>
<body>
<form action="delete.jsp" method="post">
<p><input type="text" name="theme"></p>
<p><input type="submit" value="删除"></p>
</form>
</body>
</html>
删除
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="java.sql.ResultSet"%>
<%@page import="tool.Mysqltool"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除结果页面</title>
<style type="text/css">
<style type="text/css">
th {
	border:green solid 2px;
}
td {
	border:green solid 2px;
}
</style>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String[] s={request.getParameter("theme")};
String sql="select * from `activity` where`主题`=?";
ResultSet res=Mysqltool.executequ(Mysqltool.getcon(), sql, s);
%>
<table>
  <tr>
    <th>主题</th>
    <th>目的</th>
    <th>类型</th>
    <th>时间</th>
    <th>地点</th>
    <th>对象</th>
    <th>内容</th>
    <th>日程安排</th>
  </tr>

<%
		while(res.next()){
%>
  <tr>
    <td><%=res.getString("主题") %></td>
    <td><%=res.getString("目的") %></td>
    <td><%=res.getString("类型") %></td>
    <td><%=res.getString("时间") %></td>
    <td><%=res.getString("地点") %></td>
    <td><%=res.getString("对象") %></td>
    <td><%=res.getString("内容") %></td>
    <td><%=res.getString("日程安排") %></td>
  </tr>
<%
		}
%>
</table>
<script type="text/javascript">
window.alert('是否删除')
</script>
<%
sql="delete from `activity` where`主题`=?";
Mysqltool.executeup(Mysqltool.getcon(), sql, s);
Mysqltool.Close();
%>
<script type="text/javascript">
window.alert('删除成功')
location.assign("Main interface.html");
</script>
</body>
</html>
浏览
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="java.sql.ResultSet"%>
<%@page import="tool.Mysqltool"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除结果页面</title>
<style type="text/css">
<style type="text/css">
th {
	border:green solid 2px;
}
td {
	border:green solid 2px;
}
</style>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String[] s={request.getParameter("theme")};
String sql="select * from `activity` where`主题`=?";
ResultSet res=Mysqltool.executequ(Mysqltool.getcon(), sql, s);
%>
<table>
  <tr>
    <th>主题</th>
    <th>目的</th>
    <th>类型</th>
    <th>时间</th>
    <th>地点</th>
    <th>对象</th>
    <th>内容</th>
    <th>日程安排</th>
  </tr>

<%
		while(res.next()){
%>
  <tr>
    <td><%=res.getString("主题") %></td>
    <td><%=res.getString("目的") %></td>
    <td><%=res.getString("类型") %></td>
    <td><%=res.getString("时间") %></td>
    <td><%=res.getString("地点") %></td>
    <td><%=res.getString("对象") %></td>
    <td><%=res.getString("内容") %></td>
    <td><%=res.getString("日程安排") %></td>
  </tr>
<%
		}
%>
</table>
<script type="text/javascript">
window.alert('是否删除')
</script>
<%
sql="delete from `activity` where`主题`=?";
Mysqltool.executeup(Mysqltool.getcon(), sql, s);
Mysqltool.Close();
%>
<script type="text/javascript">
window.alert('删除成功')
location.assign("Main interface.html");
</script>
</body>
</html>
浏览
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="java.sql.ResultSet"%>
<%@page import="tool.Mysqltool"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>详细信息页面</title>
<style type="text/css">
th {
	border:green solid 2px;
}
td {
	border:green solid 2px;
}
</style>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
ServletContext con=this.getServletContext();
String[] s={(String)con.getAttribute("theme")};
String sql="select * from `activity` where`主题`=?";
ResultSet res=Mysqltool.executequ(Mysqltool.getcon(), sql, s);
%>
<table>
  <tr>
    <th>主题</th>
    <th>目的</th>
    <th>类型</th>
    <th>时间</th>
    <th>地点</th>
    <th>对象</th>
    <th>内容</th>
    <th>日程安排</th>
  </tr>

<%
		while(res.next()){
%>
  <tr>
    <td><%=res.getString("主题") %></td>
    <td><%=res.getString("目的") %></td>
    <td><%=res.getString("类型") %></td>
    <td><%=res.getString("时间") %></td>
    <td><%=res.getString("地点") %></td>
    <td><%=res.getString("对象") %></td>
    <td><%=res.getString("内容") %></td>
    <td><%=res.getString("日程安排") %></td>
  </tr>
<%
}
Mysqltool.Close();
%>
</table>
</body>
</html>
查询
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询页面</title>
</head>
<body>
<form action="browse.jsp" method="post">
<p><input type="text" name="theme"></p>
<p><input type="text" name="time"></p>
<p><input type="text" name="kind"></p>
<p><input type="text" name="people"></p>
<p><input type="submit"></p>
</form>
</body>
</html>
posted @ 2022-11-03 17:52  突破铁皮  阅读(38)  评论(0编辑  收藏  举报