社团管理系统(part2)

目录

part2实现社团与社团活动的创建、查找、删除、统计功能

一、创建社团与社团活动两张表

二、今天要实现的界面大致浏览 

 三、代码部分(重点部分讲解)


part2实现社团与社团活动的创建、查找、删除、统计功能

今天的部分完成社团管理系当中的社团以及社团活动查找、删除、概览统计功能,在社团与社团活动之间实现关联关系。

一、创建社团与社团活动两张表

二、今天要实现的界面大致浏览 

 三、代码部分(重点部分讲解)

1.登录权限设置(未登录则无法使用管理员功能)

使用session来实现管理权限,在管理员登录页面提交表单后,跳转到AdminLogServlet.java.

将ok(或者自己随便什么自定义的符号代表)设置给creaacmsg(自定义设置)如下面的request.getSession().setAttribute("creaacmsg","ok");

AdminLogServlet.java代码

package com.admin;

import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AdminLogServlet")
public class AdminLogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String adminUsername=request.getParameter("adminUsername");
		String adminPassword=request.getParameter("adminPassword");
		String vcode1=request.getParameter("veri");
        String s_v = (String) request.getSession().getAttribute("v");
        
        if(!vcode1.equals(s_v)) {
			request.getSession().setAttribute("adminLogMsg","请输入正确的二维码");
			request.getRequestDispatcher("AdminLogin.jsp").forward(request,response);
		}
        else {
        	try {
    			int t=AdminService.adminLogin(adminUsername, adminPassword);
    			if(t==404) {
	        		request.getSession().setAttribute("adminLogMsg","用户名或密码不正确.");
	        		request.getRequestDispatcher("AdminLogin.jsp").forward(request,response);
			}
	        	else {
	        		request.getSession().setAttribute("adminChangerMsg","ok");
	        		request.getSession().setAttribute("adminUsername", adminUsername);
	        		request.getSession().setAttribute("creaclubmsg","ok");
	        		request.getSession().setAttribute("creaacmsg","ok");
	        		request.getSession().setAttribute("deleclubmsg","ok");
	        		request.getRequestDispatcher("AdminLogsucc.jsp").forward(request,response);
	        	}
    		} catch (SQLException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    			System.out.print("no");
    		}
			
        }
	}
}

然后再点击创建社团的页面CreatClubActivity.jsp,获取到session传来的“creaacmsg”,判断是否正确或为空,正确则可以使用权限

CreatClubActivity.jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="bootstrap-4.6.1-dist/css/bootstrap.min.css">
<title>Insert title here</title>
</head>
<body>
<script src="bootstrap-4.6.1-dist/jquery-3.6.0.min.js"></script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.bundle.min.js"></script>
</body>
<div class="container">
<%@include file="nav.jsp" %>
  <div class="row" style="margin-top:10px">
	<%@include file="AdminLeftcol.jsp" %>
	<div class="col-7">
      <div class="card">
  	  <div class="card-body">
  	  <% 
		String creaacmsg =(String) session.getAttribute("creaacmsg");
		if (creaacmsg==null) { %>
      	<div style="color:red;text-align:left"><%="请先登录"%></div>
		<% session.removeAttribute("creaacmsg");
	} else { %>
      <form action="/CommunityManager/CreateActivityServlet" method="post">
  		<div class="form-group row">
    		<label for="InputLeader">活动负责人</label>
    		<div class="col-sm-10">
			<input type="text" name="acLeader" class="form-control" id="InputLeaderid">
    		</div>
    	</div>
    	
  		<div class="form-group row">
    		<label for="InputHClub">举办社团</label>
    		<div class="col-sm-10">
			<input type="text" name="holdClub" class="form-control" id="InputHoldClub">
    		</div>
  		</div>
   		
   		<div class="form-group row">
    		<label for="InputHoldContents">活动内容</label>
    		<div class="col-sm-10">
			<input type="text" name="holdContents" class="form-control" id="InputholdContents">
    		</div>
  		</div>
   		
   		<div class="form-group row">
    		<label for="InputholdTime">活动时间</label>
    		<div class="col-sm-10">
			<input type="date" name="holdTime" class="form-control" id="InputholdTime">
    		</div>
  		</div>
   
   		<div class="form-group row">
    		<label for="InputholdPlace">举办地点</label>
    		<div class="col-sm-10">
			<input type="text" name="holdPlace" class="form-control" id="InputholdPlace">
    		</div>
  		</div>
   
  		<div class="form-group row">
  			<label for="Inputveri">校验码</label>
  			<div class="col-sm-3">
    		<img id="vericode" src="Vericode" onclick="this.src=this.src+'?'+Math.random()" width="80" height="30">
    		</div>
  			<div class="col-sm-5">
    		<input type="text" name="veri" class="form-control" id="InputPasswordid2">
    		</div>
    		<div class="col-sm-5">
    		<button id="btn" onclick="document.getElementById('vericode').click()" >刷新验证码</button>
    		</div>
  		</div>
  		
  		<div class="form-group row">
  			<div class="col-sm-10">
  				<button type="submit" class="btn btn-primary">发布</button>
  			</div>
  		</div>
	</form>
	<%} %>
  	</div>
</div>
</div>
  </div>
</div>
</html>

2.删除功能的实现

权限功能和上面一致,删除功能我这里 是直接加了一个按钮。在点击进入删除界面的时候,我们先在servlet里面获取到所有的社团活动(servlet里可以通过service方法中获取到社团活动值,这样比较简洁),获取到后再跳转到删除页面,按钮通过链接实现功能,根据id号操作删除。

<td><a class="btn btn-outline-danger" href="http://localhost:1090/CommunityManager/ClubDeleteServlet?id=${clublist.id}" role="button">删除</a></td>

点击删除社团活动先进入到ClubDeleteListServlet.java获取所有活动的值,然后跳转到删除页面 

package com.club;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.activity.club_activity;

@WebServlet("/ClubDeleteListServlet")
public class ClubDeleteListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
			List<club_activity> clublist=ClubService.getActivityList();
			request.setAttribute("clublist", clublist);
			request.getRequestDispatcher("ClubDeleteList.jsp").forward(request, response);
	}

}

 这就是跳转后的界面ClubDeleteList.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
	href="bootstrap-4.6.1-dist/css/bootstrap.min.css">
<title>Insert title here</title>
</head>
<body>
</body>
<div class="container">
		<%@include file="nav.jsp"%>
	<div class="row" style="margin-top: 10px">
		<%@include file="AdminLeftcol.jsp" %>
		<div class="col-10">
		<% 
		String deleclubmsg =(String) session.getAttribute("deleclubmsg");
		if (deleclubmsg==null) { %>
      	<div style="color:red;text-align:left"><%="请先登录"%></div>
		<% session.removeAttribute("deleclubmsg");
	} else { %>
				<table class="table">
					<thead>
						<tr>
							<th scope="col" width="10%">活动编码</th>
							<th scope="col" width="20%">活动举办人</th>
							<th scope="col" width="20%">活动举办社团</th>
							<th scope="col" width="20%">活动内容</th>
							<th scope="col" width="20%">活动时间</th>
							<th scope="col" width="10%">活动地点</th>
							
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${clublist}" var="clublist">
							<tr>
								<th scope="row">${clublist.id}</th>
								<td>${clublist.activity_leader}</td>
								<td>${clublist.holding_club}</td>
								<td>${clublist.holding_contents}</td>
								<td>${clublist.holding_time}</td>
								<td>${clublist.holding_place}</td>
								<td><a class="btn btn-outline-danger" href="http://localhost:1090/CommunityManager/ClubDeleteServlet?id=${clublist.id}" role="button">删除</a></td>
						</tr>
						</c:forEach>
					</tbody>
				</table>
				<%} %>
			</div>
		</div>
	</div></html>

跳转到链接里的servlet里进行删除操作后回到删除界面,实现删除操作,如下为链接中的servlet,调用的方法里实现删除功能。

package com.club;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.activity.club_activity;

@WebServlet("/ClubDeleteServlet")
public class ClubDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String idd=request.getParameter("id");
		int id=Integer.parseInt(idd);
		List<club_activity> clublist=ClubService.getClubDeleteList(id);
		request.setAttribute("clublist", clublist);
		request.getRequestDispatcher("ClubDeleteList.jsp").forward(request, response);
	}
    
}

3.根据创建的时间查询社团

也是点击ClubQueryServlet.java获取到社团的值后跳转到ClubQueryInfo.jsp,在此获取到指定日期后,再跳转到ClubQueryInfoServlet.java获取到指定日期的社团后再传入到ClubQueryInfo.jsp界面。

ClubQueryServlet.java代码

package com.club;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ClubQueryServlet")
public class ClubQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<club> list=ClubService.getClubList();
		request.setAttribute("list", list);
		request.getRequestDispatcher("ClubQueryInfo.jsp").forward(request, response);
	}
}

ClubQueryInfo.jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
	href="bootstrap-4.6.1-dist/css/bootstrap.min.css">
<title>Insert title here</title>
</head>
<body>
</body>
<div class="container">
		<%@include file="nav.jsp"%>
	<div class="row" style="margin-top: 10px">
		<%@include file="ClubLeftcol.jsp" %>
		<div class="col-12">
				<form action="ClubQueryInfoServlet">
					<input type="date" name="q_date">
					<input type="submit" name="查询">
				</form>
				<table class="table">
					<thead>
						<tr>
							<th scope="col" width="10%">社团编码</th>
							<th scope="col" width="30%">社团名称</th>
							<th scope="col" width="30%">创立人</th>
							<th scope="col" width="30%">创始时间</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${list}" var="clublist">
							<tr>
								<th scope="row">${clublist.id}</th>
								<td>${clublist.name}</td>
								<td>${clublist.founder}</td>
								<td>${clublist.found_time}</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				
			</div>
		</div>
	</div>
</html>

ClubQueryInfoServlet.java代码

package com.club;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ClubQueryInfo
 */
@WebServlet("/ClubQueryInfoServlet")
public class ClubQueryInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String day=request.getParameter("q_date");
		List<club> list=ClubService.getClubByDay(day);
		request.setAttribute("list", list);
		request.getRequestDispatcher("ClubQueryInfo.jsp").forward(request, response);
	}

}

4.概览统计功能的实现

进入查询界面后的活动概览,我是通过一个链接进入的

<a href="http://localhost:1090/CommunityManager/ActivityTotalServlet" class="list-group-item list-group-item-action active" aria-current="true">活动概览</a>

然后链接到ActivityTotalServlet.java界面获取到对应社团所举办的活动个数,这里新建了一个activity_count类,便于呈现社团对应活动个数和写SQL语句,然后跳转到ActivityTotal.jsp,这个界面可以·对应社团的活动详情。链接里也同时是通过传值然后获取对应的界面。

<td><a href="ActivityDetailServlet?holding_club=${clublist.holding_club}">详细情况</a></td>

代码部分其实和上面差不多,就是在servlet操作和jsp展示,数据库操作通过对应类获取值。

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、项目简介本课程演示的是一套基于SSM实现的社团管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。课程包含:1. 项目源码、项目文档、数据库脚本、软件工具等所有资料2. 带你从零开始部署运行本套系统3. 该项目附带的源码资料可作为毕设使用4. 提供技术答疑二、技术实现后台框架:Spring、SpringMVC、MyBatisUI界面:JSP、jQuery 、H-ui数据库:MySQL 三、系统功能本社团管理系统是根据大学社团管理的实际应用而开发的,采用JSP技术,JAVA编程语言,基于SSM框架,使用MySQL数据库,充分保证系统的安全性和稳定性,使得社团管理工作系统化、规范化、高效化。该系统主要分为前台和后台两大功能模块,共包含两个角色:用户、管理员。具体的系统功能如下:1.前台功能 前台首页、新闻公告、规章制度、社团活动、活动报名、互动交流、用户注册、用户登陆、用户中心、修改密码、个人信息、我的社团活动、物资申请、退出登陆等功能。2.后台功能 后台系统登陆、社团用户管理、管理员管理、网站公告管理、社团活动管理、申请类型管理、用户申请管理、活动报名管理、留言交流管理等功能。该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 四、项目截图1)前台首页2)新闻公告3)用户注册4)社团用户管理5)社团活动管理  更多Java毕设项目请关注【毕设系列课程】https://edu.csdn.net/lecturer/2104   

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值