首页 > 其他分享 >校园活动管理系统

校园活动管理系统

时间:2022-12-22 12:55:07浏览次数:35  
标签:String 管理系统 request 校园 zhuti public 活动 huodong

一、题目

校园社团活动管理系统(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分。)

二、思路

 

 

 

三、代码

使用mybatis+Mapper代理来实现功能

使用到的jar包:mybatis、jQuery(进行js校验)、mysql

1.mysql.properties(配置文件)

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/course?serverTimezone=UTC&useSSL=false&characterEncoding=UTF-8
username=root
password=123456

2.mybatis-config.xml(配置文件)

 
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <properties resource="mysql.properties"/>
    <!--  对事物的管理和连接池的配置  -->
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <!--连接池信息-->
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>

<!--mappers映射器-->
    <mappers>
         <!--映射文件方式2.自动扫描包内的Mapper接口和配置文件-->
        <package name="com.xxxx.mapper"/>
    </mappers>
</configuration>
 

3.HuodongMapper.java (Mapper接口类)

 
package com.xxxx.mapper;

import com.xxxx.entity.Huodong;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface HuodongMapper {
    void add(Huodong huodong);

    List<Huodong> selectBylessThanId(int id);

    Huodong selectByZhuti(String zhuti);

    void update(@Param("huodong") Huodong huodong,@Param("id") int id);

    void deleteById(int id);

    List<Huodong> selectAll();

    Huodong chaxunBytiaojian(@Param("zhuti") String zhuti,@Param("time") String time,@Param("type") String type,@Param("place") String place);

}
 

4.HuodongMapper.xml(Mapper.xml配置文件)

 
<?xml version="1.0" encoding="UTF-8"?>
<!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"-->
<!--         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"-->
<!--         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"-->
<!--         version="4.0">-->
<!--</web-app>-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace:命名空间-->
<mapper namespace = "com.xxxx.mapper.HuodongMapper">
 
    <insert id="add" useGeneratedKeys="true" keyProperty="id">
        insert into huodong01 (zhuti,mudi,type,time,place,duixiang,neirong,anpai)
        values (#{zhuti},#{mudi},#{type},#{time},#{place},#{duixiang},#{neirong},#{anpai});
    </insert>
    <select id="selectBylessThanId" resultType="com.xxxx.entity.Huodong">
        select * from huodong01 where id <![CDATA[
        <
        ]]> #{id};
    </select>

    <select id="selectByZhuti" resultType="com.xxxx.entity.Huodong">
        select * from huodong01 where zhuti = #{zhuti};
    </select>
    <select id="selectAll" resultType="com.xxxx.entity.Huodong">
        select  * from huodong01
    </select>
    <select id="chaxunBytiaojian" resultType="com.xxxx.entity.Huodong">
        select * from huodong01
                 <where>
                     <if test="zhuti !=null and zhuti !=''">
                        and zhuti like #{zhuti}
                     </if>
                     <if test="time !=null and time != ''">
                         and time like #{time}
                     </if>
                     <if test="type !=null and type != ''">
                         and type like #{type}
                     </if>
                     <if test="place !=null and place != ''">
                         and place like #{place}
                     </if>
                 </where>
    </select>

    <update id="update">
        update huodong01 set
                             zhuti=#{huodong.zhuti},mudi=#{huodong.mudi},type=#{huodong.type},time=#{huodong.time},
                             place=#{huodong.place},  duixiang=#{huodong.duixiang},neirong=#{huodong.neirong},anpai=#{huodong.anpai}
        where id=#{id};
    </update>

    <delete id="deleteById">
        delete from huodong01 where id=#{id};
    </delete>

</mapper>
 

5.GetSqlSession.java(工具类:负责返回sqlsession对象)

 
package com.xxxx.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;

public class GetSqlSession {
    /**
     * 获取SqlSession对象
     */
    public static SqlSession CreateSqlSession() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //获取SqlSession对象
        SqlSession sqlSession = sqlSessionFactory.openSession(true);//关闭事物,否则要手动提交事务
        return sqlSession;
    }
}
 

6.IsNull.java(工具类:判断字符串是否为null或者空字符串)

 
package com.xxxx.util;

/**
 * 工具类:判断是否为空字符串或者null
 */
public class IsNull {
    public static boolean isNull(String str){
        if(str==null||"".equals(str.trim())){
            return true;
        }
        return false;
    }
}
 

7.Huodong.java(实体类)

 
package com.xxxx.entity;

public class Huodong {
    private int id;
    private String zhuti;
    private String mudi;
    private String type;
    private String time;
    private String place;
    private String duixiang;
    private String neirong;
    private String anpai;

    public Huodong() {
    }

    public Huodong(String zhuti, String mudi, String type, String time, String place, String duixiang, String neirong, String anpai) {
        this.zhuti = zhuti;
        this.mudi = mudi;
        this.type = type;
        this.time = time;
        this.place = place;
        this.duixiang = duixiang;
        this.neirong = neirong;
        this.anpai = anpai;
    }

    public Huodong(int id, String zhuti, String mudi, String type, String time, String place, String duixiang, String neirong, String anpai) {
        this.id = id;
        this.zhuti = zhuti;
        this.mudi = mudi;
        this.type = type;
        this.time = time;
        this.place = place;
        this.duixiang = duixiang;
        this.neirong = neirong;
        this.anpai = anpai;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getZhuti() {
        return zhuti;
    }

    public void setZhuti(String zhuti) {
        this.zhuti = zhuti;
    }

    public String getMudi() {
        return mudi;
    }

    public void setMudi(String mudi) {
        this.mudi = mudi;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = 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 getDuixiang() {
        return duixiang;
    }

    public void setDuixiang(String duixiang) {
        this.duixiang = duixiang;
    }

    public String getNeirong() {
        return neirong;
    }

    public void setNeirong(String neirong) {
        this.neirong = neirong;
    }

    public String getAnpai() {
        return anpai;
    }

    public void setAnpai(String anpai) {
        this.anpai = anpai;
    }
}
 

8.yemian.jsp(总页面)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>校园社团活动管理系统</title>
</head>
<body>
<h2 align="center">校园社团活动管理系统</h2>
<a href="fabu.jsp">发布活动信息</a><br>
<a href="xiugai.jsp">修改活动信息</a><br>
<a href="delete.jsp">删除活动信息</a><br>
<a href="chaxun.jsp">查询活动信息</a><br>
<a href="liulan.jsp">浏览消息页面</a>
</body>
</html>
 

9.fabu.jsp(发布页面:添加信息页面)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>发布活动信息</title>
</head>
<body>
<h2 align="center">发布活动信息</h2>
<form method="post" action="fabuServlet" id="fabuForm">
    <table border="1" width="800">
        <tr>
            <td>活动主题</td>
            <td><input type="text" name="zhuti" id="zhuti"></td>
        </tr>
        <tr>
            <td>活动目的</td>
            <td>
                <input type="text" name="mudi" id="mudi">
            </td>
        </tr>
        <tr>
            <td>活动类型</td>
            <td>
                <input type="radio" name="type" value="社团竞赛">社团竞赛<br>
                <input type="radio" name="type" value="野外采风">野外采风<br>
                <input type="radio" name="type" value="校内集会">校内集会<br>
                <input type="radio" name="type" value="社团纳新">社团纳新<br>
            </td>
        </tr>
        <tr>
            <td>活动时间</td>
            <td>
                <input type="text" name="time">
            </td>
        </tr>
        <tr>
            <td>
                活动地点
            </td>
            <td><input type="text" name="place"></td>
        </tr>
        <tr>
            <td>活动对象</td>
            <td>
                <input type="checkbox" name="duixiang" value="社团成员">社团成员<br>
                <input type="checkbox" name="duixiang" value="全体学生">全体学生<br>
            </td>
        </tr>
        <tr>
            <td>活动内容</td>
            <td>
                <input type="text" name="neirong" id="neirong">
            </td>
        </tr>
        <tr>
            <td>活动日程安排</td>
            <td><input type="text" name="anpai" id="anpai"> </td>
        </tr>
        <tr>
            <td>提示信息</td>
            <td>
            <span id="msg1" style="color: red"></span><br>
            <span id="msg2" style="color: red"></span><br>
            <span id="msg3" style="color: red"></span><br>
            <span id="msg4" style="color: red"></span><br>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2"><button type="button" id="tijiaoBtn">提交</button></td>
        </tr>
    </table>
</form>
</body>

<%--JS校验:zhuti20,mudi50,neirong500,anpai500--%>
<script type="text/javascript" src="js/jquery-3.6.1.js"></script>
<script type="text/javascript">
    //点击shijian
    $("#tijiaoBtn").click(function(){
        var zhuti=$("#zhuti").val();
        var mudi=$("#mudi").val();
        var neirong=$("#neirong").val();
        var anpai=$("#anpai").val();
        var find=0;
        if(zhuti.length>20){
            find=1;
            $("#msg1").html("活动主题长度超过20");
        }
        if(mudi.length>20){
            find=1;
            $("#msg2").html("活动目的长度超过50");
        }
        if(neirong.length>20){
            find=1;
            $("#msg3").html("活动内容长度超过500");
        }
        if(anpai.length>20){
            find=1;
            $("#msg4").html("活动日程安排长度超过500");
        }
        //提交信息
        if(find==0){
            $("#fabuForm").submit();
        }
    })
</script>
</html>
 

10.fabuServlet.java(负责接收发布消息表格提交后的信息)

 
package com.xxxx.servlet;

import com.xxxx.entity.Huodong;
import com.xxxx.mapper.HuodongMapper;
import com.xxxx.util.GetSqlSession;
import org.apache.ibatis.session.SqlSession;

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 java.io.IOException;

@WebServlet("/fabuServlet")
public class fabuServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置->获取域对象->SqlSeesion->Mapper->caozuo->close()
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
         String zhuti   =request.getParameter("zhuti")   ;
         String mudi    =request.getParameter("mudi")   ;
         String type    =request.getParameter("type")   ;
         String time    =request.getParameter("time")    ;
         String place   =request.getParameter("place")   ;
         String duixiang=request.getParameter("duixiang")   ;
         String neirong =request.getParameter("neirong")    ;
         String anpai   =request.getParameter("anpai")    ;
         //封装对象
        Huodong huodong = new Huodong(zhuti,mudi,type,time,place,duixiang,neirong,anpai);
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        huodongMapper.add(huodong);
        int id = huodong.getId();
        request.setAttribute("huodong",huodong);
        request.setAttribute("id",id);
        request.getRequestDispatcher("fabuxiansi.jsp").forward(request,response);
        sqlSession.close();
    }
}
 

11.fabuxiansi.jsp(添加完毕后的页面显示,其中最新添加的置顶显示)

 
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.xxxx.util.GetSqlSession" %>
<%@ page import="com.xxxx.entity.Huodong" %>
<%@ page import="java.util.List" %>
<%@ page import="com.xxxx.mapper.HuodongMapper" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>发布信息显示页面</title>
</head>
<body>
<h2 align="center">发布信息显示页面</h2>
<table align="center" border="1" width="800">
    <tr>
        <td>活动主题</td>
        <td>活动目的</td>
        <td>活动类型</td>
        <td>活动时间</td>
        <td>活动地点</td>
        <td>活动对象</td>
        <td>活动内容</td>
        <td>活动日程安排</td>
    </tr>
    <tr style="color: red">
        <%--   取值的方式     --%>
        <td>${huodong.zhuti}</td>
        <td>${huodong.mudi}</td>
        <td>${huodong.type}</td>
        <td>${huodong.time}</td>
        <td>${huodong.place}</td>
        <td>${huodong.duixiang}</td>
        <td>${huodong.neirong}</td>
        <td>${huodong.anpai}</td>
    </tr>
        <%
        int id= (int) request.getAttribute("id");//注意,用request就好了
        SqlSession sqlSession= GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper=sqlSession.getMapper(HuodongMapper.class);
        List<Huodong> huodongs = huodongMapper.selectBylessThanId(id);//查询
        for (Huodong huodong:huodongs) {
    %>
    <tr>
        <td><%=huodong.getZhuti()%></td>
        <td><%=huodong.getMudi()%></td>
        <td><%=huodong.getType()%></td>
        <td><%=huodong.getTime()%></td>
        <td><%=huodong.getPlace()%></td>
        <td><%=huodong.getDuixiang()%></td>
        <td><%=huodong.getNeirong()%></td>
        <td><%=huodong.getAnpai()%></td>
    </tr>
        <%
        }
    %>
</body>
</html>
 

12.xiugai.jsp(修改页面:输入要修改的主题)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改活动信息</title>
</head>
<body>
<h2 align="center">修改活动信息</h2>
<form method="post" action="xiugaiServlet">
    活动主题:<input type="text" name="zhuti">
    <button>显示信息</button>
</form>
</body>
</html>
 

13.xiugaiServlet.java(接收修改页面提交过来的信息,如果主题不存在就提示错误信息并且返回页面,存在则进入修改页面)

 
package com.xxxx.servlet;


import com.xxxx.entity.Huodong;
import com.xxxx.mapper.HuodongMapper;
import com.xxxx.util.GetSqlSession;
import org.apache.ibatis.session.SqlSession;

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 java.io.IOException;

@WebServlet("/xiugaiServlet")
public class xiugaiServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String zhuti=request.getParameter("zhuti");
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        Huodong huodong=huodongMapper.selectByZhuti(zhuti);
        if(huodong==null){
            response.getWriter().write("该活动不存在");
            response.getWriter().close();
        }else{
            request.setAttribute("huodong",huodong);
            request.setAttribute("id",huodong.getId());
            request.getRequestDispatcher("xiugai02.jsp").forward(request,response);
        }
        sqlSession.close();
    }
}
 

14.xiugai02.jsp(修改页面:进行修改)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改页面</title>
</head>
<body>
<%
    int id= (int)request.getAttribute("id");
    session.setAttribute("id",id);
%>
<h2 align="center">修改页面</h2>
<table align="center" border="1" width="800">
    <form method="post" action="xiugaiServlet02" id="xiugaiForm">
        <tr>
            <td>活动主题</td>
            <td>${huodong.zhuti}</td>
            <td>修改:<input type="text" name="zhuti" id="zhuti"></td>
        </tr>
        <tr>
            <td>活动目的</td>
            <td>${huodong.mudi}</td>
            <td>修改:
                <input type="text" name="mudi" id="mudi">
            </td>
        </tr>
        <tr>
            <td>活动类型</td>
            <td>${huodong.type}</td>
            <td>修改:
                <input type="radio" name="type" value="社团竞赛">社团竞赛<br>
                <input type="radio" name="type" value="野外采风">野外采风<br>
                <input type="radio" name="type" value="校内集会">校内集会<br>
                <input type="radio" name="type" value="社团纳新">社团纳新<br>
            </td>
        </tr>
        <tr>
            <td>活动时间</td>
            <td>${huodong.time}</td>
            <td>修改:
                <input type="text" name="time">
            </td>
        </tr>
        <tr>
            <td>
                活动地点
            </td>
            <td>${huodong.place}</td>
            <td>修改:<input type="text" name="place"></td>
        </tr>
        <tr>
            <td>活动对象</td>
            <td>${huodong.duixiang}</td>
            <td>修改:
                <input type="checkbox" name="duixiang" value="社团成员">社团成员<br>
                <input type="checkbox" name="duixiang" value="全体学生">全体学生<br>
            </td>
        </tr>
        <tr>
            <td>活动内容</td>
            <td>${huodong.neirong}</td>
            <td>修改:
                <input type="text" name="neirong" id="neirong">
            </td>
        </tr>
        <tr>
            <td>活动日程安排</td>
            <td>${huodong.anpai}</td>
            <td><input type="text" name="anpai" id="anpai"> </td>
        </tr>
        <tr>
            <td>提示信息</td>
            <td colspan="2">
                <span id="msg1" style="color: red"></span><br>
                <span id="msg2" style="color: red"></span><br>
                <span id="msg3" style="color: red"></span><br>
                <span id="msg4" style="color: red"></span><br>
            </td>
        </tr>
        <tr align="center">
            <td colspan="3"><button type="button" id="tijiaoBtn">提交</button></td>
        </tr>
    </form>
</table>
</body>
<script type="text/javascript" src="js/jquery-3.6.1.js"></script>
<script type="text/javascript">
    //点击shijian
    $("#tijiaoBtn").click(function(){
        var zhuti=$("#zhuti").val();
        var mudi=$("#mudi").val();
        var neirong=$("#neirong").val();
        var anpai=$("#anpai").val();
        var find=0;
        if(zhuti.length>20){
            find=1;
            $("#msg1").html("活动主题长度超过20");
        }
        if(mudi.length>20){
            find=1;
            $("#msg2").html("活动目的长度超过50");
        }
        if(neirong.length>20){
            find=1;
            $("#msg3").html("活动内容长度超过500");
        }
        if(anpai.length>20){
            find=1;
            $("#msg4").html("活动日程安排长度超过500");
        }
        //提交信息
        if(find==0){
            $("#xiugaiForm").submit();
        }
    })
</script>
</html>
 

15.xiugaiServlet02.java(接收要修改的信息,然后对数据库进行修改)

 
@WebServlet("/deleteServlet02")
public class deleteServlet02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String zhuti=request.getParameter("zhuti");
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        //获取id
        int id= (int) request.getSession().getAttribute("id");
        huodongMapper.deleteById(id);
        response.getWriter().write("删除成功");
        response.getWriter().close();
        sqlSession.close();

    }
}
 

16.delete.jsp(删除页面:输入要删除的主题)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除活动信息</title>
</head>
<body>
<h2 align="center">删除活动信息</h2>
<form method="post" action="deleteServlet">
    活动主题:<input type="text" name="zhuti">
    <button>显示信息</button>
</form>
</body>
</html>
 

17.deleteServlet.java(接收要删除的主题,进行判断,若主题不存在就提示错误信息,存在就进入删除页面)’

 
@WebServlet("/deleteServlet")
//和修改Servlet都一样
public class deleteServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String zhuti=request.getParameter("zhuti");
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        Huodong huodong=huodongMapper.selectByZhuti(zhuti);
        if(huodong==null){
            response.getWriter().write("该活动不存在");
            response.getWriter().close();
        }else{
            request.setAttribute("huodong",huodong);
            request.setAttribute("id",huodong.getId());
            request.getRequestDispatcher("delete02.jsp").forward(request,response);
        }
        sqlSession.close();

    }
}
 

18.delete02.jsp(删除页面:选择是否删除)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除消息显示页面</title>
</head>
<body>
<%
    int id = (int) request.getAttribute("id");
    session.setAttribute("id",id);
%>
<h2 align="center">删除消息显示页面</h2>
<table align="center" border="1" width="800">
    <form method="post" action="deleteServlet02">
    <tr>
        <td>活动主题</td>
        <td>活动目的</td>
        <td>活动类型</td>
        <td>活动时间</td>
        <td>活动地点</td>
        <td>活动对象</td>
        <td>活动内容</td>
        <td>活动日程安排</td>
    </tr>
    <tr style="color: red">
        <%--   取值的方式     --%>
        <td>${huodong.zhuti}</td>
        <td>${huodong.mudi}</td>
        <td>${huodong.type}</td>
        <td>${huodong.time}</td>
        <td>${huodong.place}</td>
        <td>${huodong.duixiang}</td>
        <td>${huodong.neirong}</td>
        <td>${huodong.anpai}</td>
    </tr>
        <tr>
            <td colspan="6">
                是否确认删除该活动信息
            </td>
            <td colspan="2">
                <button>确定</button>
            </td>
        </tr>
    </form>
</table>
</body>
</html>
 

19.deleteServlet02.java(接收要删除的信息进行删除)

 
@WebServlet("/deleteServlet02")
public class deleteServlet02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String zhuti=request.getParameter("zhuti");
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        //获取id
        int id= (int) request.getSession().getAttribute("id");
        huodongMapper.deleteById(id);
        response.getWriter().write("删除成功");
        response.getWriter().close();
        sqlSession.close();

    }
}
 

20.chaxun.jsp(模糊查询页面:填入信息,可以全部填完也可以不填完,实现模糊查询)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询活动信息</title>
</head>
<body>
<h2 align="center">查询活动信息</h2>
<form method="post" action="chaxunServlet">
    活动主题:<input type="text" name="zhuti"><br>
    活动时间:<input type="text" name="time"><br>
    活动类型:<input type="text" name="type"><br>
    活动地点:<input type="text" name="place"><br>
    <button>查询</button>
</form>
</body>
</html>
 

21.chaxunServlet.java(接收要查询的信息,进行模糊查询)

 
@WebServlet("/chaxunServlet")
public class chaxunServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String  zhuti=request.getParameter("zhuti");
        String  time=request.getParameter("time");
        String  type=request.getParameter("type");
        String  place=request.getParameter("place");
        if(!IsNull.isNull(zhuti)){
            zhuti="%"+zhuti+"%";
        }
        if(!IsNull.isNull(time)){
            time="%"+time+"%";
        }
        if(!IsNull.isNull(type)){
            type="%"+type+"%";
        }
        if(!IsNull.isNull(place)){
            place="%"+place+"%";
        }
        SqlSession sqlSession = GetSqlSession.CreateSqlSession();
        HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
        Huodong huodong = huodongMapper.chaxunBytiaojian(zhuti,time,type,place);
        request.setAttribute("huodong",huodong);
        request.getRequestDispatcher("chaxun02.jsp").forward(request,response);
        sqlSession.close();
    }
}
 

22.chaxun02.jsp(模糊查询到的信息的显示界面,其中点击活动主题跳转详细信息的界面xiansi.jsp)

 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询显示页面</title>
</head>
<body>
<h2 align="center">查询显示页面</h2>
<table align="center" width="800" border="1">
<tr>
    <td>活动主题</td>
    <td>活动类型</td>
    <td>活动时间</td>
    <td>活动对象</td>
</tr>
<tr>
    <td><a href="xiansi.jsp?zhuti=${huodong.getZhuti()}" >${huodong.getZhuti()}</a></td>
    <td>${huodong.getType()}</td>
    <td>${huodong.getTime()}</td>
    <td>${huodong.getDuixiang()}</td>
</tr>
</table>
</body>
</html>
 

23.xiansi.jsp(点击主题,显示详细信息的页面)

 
<%@ page import="com.xxxx.entity.Huodong" %>
<%@ page import="com.xxxx.mapper.HuodongMapper" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.xxxx.util.GetSqlSession" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>单个主题详细信息</title>
</head>
<body>
<table align="center" border="1" width="800">
    <tr>
        <td>活动主题</td>
        <td>活动目的</td>
        <td>活动类型</td>
        <td>活动时间</td>
        <td>活动地点</td>
        <td>活动对象</td>
        <td>活动内容</td>
        <td>活动日程安排</td>
    </tr>
        <%
    String zhuti = request.getParameter("zhuti");
    SqlSession sqlSession = GetSqlSession.CreateSqlSession();
    HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
    Huodong huodong= huodongMapper.selectByZhuti(zhuti);//查询全部
%>
    <tr>
        <td><%=huodong.getZhuti()%></td>
        <td><%=huodong.getMudi()%></td>
        <td><%=huodong.getType()%></td>
        <td><%=huodong.getTime()%></td>
        <td><%=huodong.getPlace()%></td>
        <td><%=huodong.getDuixiang()%></td>
        <td><%=huodong.getNeirong()%></td>
        <td><%=huodong.getAnpai()%></td>
    </tr>
</body>
</html>
 

24.liulan.jsp(浏览信息页面,点击主题跳转详细页面)

 
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.xxxx.util.GetSqlSession" %>
<%@ page import="com.xxxx.mapper.HuodongMapper" %>
<%@ page import="com.xxxx.entity.Huodong" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 22466
  Date: 2022/10/28
  Time: 15:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览页面</title>
</head>
<body>
<h2 align="center">浏览页面</h2>
<table align="center" border="1" width="800">
    <tr>
        <td>活动主题</td>
        <td>活动类型</td>
        <td>活动时间</td>
        <td>活动对象</td>
    </tr>
<%
    SqlSession sqlSession = GetSqlSession.CreateSqlSession();
    HuodongMapper huodongMapper = sqlSession.getMapper(HuodongMapper.class);
    List<Huodong> huodongs= huodongMapper.selectAll();//查询全部
    for (Huodong huodong:huodongs) {
%>
<tr>
    <td><a href="xiansi.jsp?zhuti=<%=huodong.getZhuti()%>" ><%=huodong.getZhuti()%></a></td>
    <td><%=huodong.getType()%></td>
    <td><%=huodong.getTime()%></td>
    <td><%=huodong.getDuixiang()%></td>
</tr>
<%
    }
%>
</body>
</html>

标签:String,管理系统,request,校园,zhuti,public,活动,huodong
From: https://www.cnblogs.com/ruipengli/p/16998309.html

相关文章