首页 > 其他分享 >期中考试:校园社团活动管理系统

期中考试:校园社团活动管理系统

时间:2022-11-01 11:14:56浏览次数:58  
标签:zhu String 管理系统 期中考试 di request 社团活动 ti active

 

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

 

 

 

一、pojo

public class Active {
    private int id;
    private String zhu_ti;
    private String mu_di;
    private String lei_xing;
    private String shi_jian;
    private String di_dian;
    private String dui_xiang;
    private String nei_rong;
    private String an_pai;

    public int getId() {
        return id;
    }

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

    public String getZhu_ti() {
        return zhu_ti;
    }

    public void setZhu_ti(String zhu_ti) {
        this.zhu_ti = zhu_ti;
    }

    public String getMu_di() {
        return mu_di;
    }

    public void setMu_di(String mu_di) {
        this.mu_di = mu_di;
    }

    public String getLei_xing() {
        return lei_xing;
    }

    public void setLei_xing(String lei_xing) {
        this.lei_xing = lei_xing;
    }

    public String getShi_jian() {
        return shi_jian;
    }

    public void setShi_jian(String shi_jian) {
        this.shi_jian = shi_jian;
    }

    public String getDi_dian() {
        return di_dian;
    }

    public void setDi_dian(String di_dian) {
        this.di_dian = di_dian;
    }

    public String getDui_xiang() {
        return dui_xiang;
    }

    public void setDui_xiang(String dui_xiang) {
        this.dui_xiang = dui_xiang;
    }

    public String getNei_rong() {
        return nei_rong;
    }

    public void setNei_rong(String nei_rong) {
        this.nei_rong = nei_rong;
    }

    public String getAn_pai() {
        return an_pai;
    }

    public void setAn_pai(String an_pai) {
        this.an_pai = an_pai;
    }

    public Active(int id, String zhu_ti, String mu_di, String lei_xing, String shi_jian, String di_dian, String dui_xiang, String nei_rong, String an_pai) {
        this.id = id;
        this.zhu_ti = zhu_ti;
        this.mu_di = mu_di;
        this.lei_xing = lei_xing;
        this.shi_jian = shi_jian;
        this.di_dian = di_dian;
        this.dui_xiang = dui_xiang;
        this.nei_rong = nei_rong;
        this.an_pai = an_pai;
    }
    public Active( String zhu_ti, String mu_di, String lei_xing, String shi_jian, String di_dian, String dui_xiang, String nei_rong, String an_pai) {

        this.zhu_ti = zhu_ti;
        this.mu_di = mu_di;
        this.lei_xing = lei_xing;
        this.shi_jian = shi_jian;
        this.di_dian = di_dian;
        this.dui_xiang = dui_xiang;
        this.nei_rong = nei_rong;
        this.an_pai = an_pai;
    }

    @Override
    public String toString() {
        return "Active{" +
                "id=" + id +
                ", zhu_ti='" + zhu_ti + '\'' +
                ", mu_di='" + mu_di + '\'' +
                ", lei_xing='" + lei_xing + '\'' +
                ", shi_jian='" + shi_jian + '\'' +
                ", di_dian='" + di_dian + '\'' +
                ", dui_xiang='" + dui_xiang + '\'' +
                ", nei_rong='" + nei_rong + '\'' +
                ", an_pai='" + an_pai + '\'' +
                '}';
    }
}

 

二、jbdcUtil

public class jdbcUtil {
    public static Connection getconnection() throws  Exception {
        Connection connection=null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Class.forName("com.mysql.cj.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/active?useUnicode=true&characterEncoding=utf8","root","123456");

        return connection;
    }

    public static void close(Connection connection) throws SQLException {
        if(connection != null)
        {
            connection.close();
        }
    }
    public static void close(PreparedStatement pstmt) throws SQLException {
        if(pstmt != null)
        {
            pstmt.close();
        }
    }
    public static void close(ResultSet rs) throws SQLException {
        if(rs != null)
        {
            rs.close();
        }
    }
}

 

三、Dao

public class Dao {
    public int add(Active active) throws Exception {
        Connection connection = jdbcUtil.getconnection();
        String sql = "insert into active(zhu_ti,mu_di,lei_xing,shi_jian,di_dian,dui_xiang,nei_rong,an_pai) value(?,?,?,?,?,?,?,?)";
        PreparedStatement pstmt = null;
        pstmt =connection.prepareStatement(sql);

        pstmt.setString(1,  active.getZhu_ti());
        pstmt.setString(2,  active.getMu_di());
        pstmt.setString(3,  active.getLei_xing());
        pstmt.setString(4,  active.getShi_jian());
        pstmt.setString(5,  active.getDi_dian());
        pstmt.setString(6,  active.getDui_xiang());
        pstmt.setString(7,  active.getNei_rong());
        pstmt.setString(8,  active.getAn_pai());
        int count = pstmt.executeUpdate();

        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
    public int del(int id) throws Exception {
        Connection connection = jdbcUtil.getconnection();

        String sql = "delete from active where id = ?";

        PreparedStatement pstmt = null;

        pstmt = connection.prepareStatement(sql);

        pstmt.setInt(1, id);
        int count = pstmt.executeUpdate();
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
    public int update(Active active) throws Exception {
        Connection connection = jdbcUtil.getconnection();
        String sql = "update active\n" +
                "set zhu_ti = ?,\n" +
                "mu_di = ?,\n" +
                "lei_xing = ?,\n" +
                "shi_jian = ?,\n" +
                "di_dian = ?,\n" +
                "dui_xiang = ?,\n" +
                "nei_rong = ?, \n" +
                "an_pai = ?\n" +
                "where id = ?";

        PreparedStatement pstmt = null;

        pstmt = connection.prepareStatement(sql);
        pstmt.setString(1,  active.getZhu_ti());
        pstmt.setString(2,  active.getMu_di());
        pstmt.setString(3,  active.getLei_xing());
        pstmt.setString(4,  active.getShi_jian());
        pstmt.setString(5,  active.getDi_dian());
        pstmt.setString(6,  active.getDui_xiang());
        pstmt.setString(7,  active.getNei_rong());
        pstmt.setString(8,  active.getAn_pai());
        pstmt.setInt(9, active.getId());
        int count = pstmt.executeUpdate();

        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
    public List<Active> selectall() throws Exception {
        Connection connection = jdbcUtil.getconnection();

        String sql = "select * from active";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();

        Active active =  null;
        List<Active> list = new ArrayList<>();
        while (rs.next()) {
            int id = Integer.parseInt(rs.getString("id"));
            String zhu_ti = rs.getString("zhu_ti");
            String  mu_di = rs.getString("mu_di");
            String lei_xing = rs.getString("lei_xing");
            String  shi_jian = rs.getString("shi_jian");
            String di_dian = rs.getString("di_dian");
            String dui_xiang = rs.getString("dui_xiang");
            String nei_rong = rs.getString("nei_rong");
            String an_pai =  rs.getString("an_pai");

            active = new Active(id,zhu_ti,mu_di,lei_xing,shi_jian,di_dian,dui_xiang,nei_rong,an_pai);
            list.add(active);
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return list;
    }
    public Active getbyID(int id ) throws Exception {
        Connection connection = jdbcUtil.getconnection();

        String sql = "select * from active where id= ?";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);

        Active active=  null;
        pstmt.setInt(1,id);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            int ID = Integer.parseInt(rs.getString("id"));
            String zhu_ti = rs.getString("zhu_ti");
            String  mu_di = rs.getString("mu_di");
            String lei_xing = rs.getString("lei_xing");
            String  shi_jian = rs.getString("shi_jian");
            String di_dian = rs.getString("di_dian");
            String dui_xiang = rs.getString("dui_xiang");
            String nei_rong = rs.getString("nei_rong");
            String an_pai =  rs.getString("an_pai");

            active = new Active(ID,  zhu_ti, mu_di, lei_xing, shi_jian,di_dian, dui_xiang,nei_rong, an_pai);
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return active;
    }
    //按照姓名,模糊查询
    public Active getbyzhu_ti(String zhu_ti ) throws Exception {
        Connection connection = jdbcUtil.getconnection();
        PreparedStatement pstmt = null;
        String sql = "select * from active where zhu_ti like ?   ";
        pstmt = connection.prepareStatement(sql);
        pstmt.setString(1,  zhu_ti);

        ResultSet rs = pstmt.executeQuery();
        Active active = null;

        while (rs.next()) {
            int ID = Integer.parseInt(rs.getString("id"));
            String Zhu_ti = rs.getString("zhu_ti");
            String  mu_di = rs.getString("mu_di");
            String lei_xing = rs.getString("lei_xing");
            String  shi_jian = rs.getString("shi_jian");
            String di_dian = rs.getString("di_dian");
            String dui_xiang = rs.getString("dui_xiang");
            String nei_rong = rs.getString("nei_rong");
            String an_pai =  rs.getString("an_pai");

            active = new Active(ID,Zhu_ti, mu_di, lei_xing, shi_jian,di_dian, dui_xiang,nei_rong, an_pai);
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return active;
    }

    //返回模糊查询是否查询成功
    public int getbyzhu_ti_if(String zhu_ti) throws Exception {
        Connection connection = jdbcUtil.getconnection();
        PreparedStatement pstmt = null;
        String sql = "select * from active where zhu_ti like ?   ";
        pstmt = connection.prepareStatement(sql);
        pstmt.setString(1,  zhu_ti);

        ResultSet rs = pstmt.executeQuery();
        Active active = null;
        int count = 0;

        while (rs.next()) {
            count++;
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return count;
    }
    public List<Active> cha_xun(String zhu_ti, String lei_xing, String shi_jian, String di_dian) throws Exception {
        Connection connection = jdbcUtil.getconnection();
        PreparedStatement pstmt = null;
        String sql = "select * from active where  ";
        if (zhu_ti != "") {
             sql += "zhu_ti like '%" +zhu_ti+ "%' ";
         }
        if (lei_xing != "") {
            sql += "and lei_xing like '%" +lei_xing+ "%' ";
        }
        if (shi_jian != "") {
            sql += "and shi_jian like '%" +shi_jian+ "%' ";
        }
        if (di_dian != "") {
            sql += "and di_dian like '%" +di_dian+ "%' ";
        }
        if(zhu_ti==""&& lei_xing==""&& shi_jian==""&& di_dian=="")
        {
            sql = "select * from active";
        }
        Statement state = null;
        state = connection.createStatement();
        ResultSet rs = state.executeQuery(sql);
        Active active = null;
        List<Active> list = new ArrayList<>();
        while (rs.next()) {
            int ID = Integer.parseInt(rs.getString("id"));
            String Zhu_ti = rs.getString("zhu_ti");
            String  mu_di = rs.getString("mu_di");
            String lei_xing1 = rs.getString("lei_xing");
            String  shi_jian1 = rs.getString("shi_jian");
            String di_dian1 = rs.getString("di_dian");
            String dui_xiang = rs.getString("dui_xiang");
            String nei_rong = rs.getString("nei_rong");
            String an_pai =  rs.getString("an_pai");

            active = new Active(ID,Zhu_ti, mu_di, lei_xing1, shi_jian1,di_dian1, dui_xiang,nei_rong, an_pai);
            list.add(active);
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return list;
    }

    public int cha_xun_if(String zhu_ti, String lei_xing, String shi_jian, String di_dian)  throws Exception{
        Connection connection = jdbcUtil.getconnection();
        PreparedStatement pstmt = null;
        String sql = "select * from active where  ";
        if (zhu_ti != "") {
            sql += "zhu_ti like '%" +zhu_ti+ "%' ";
        }
        if (lei_xing != "") {
            sql += "and lei_xing like '%" +lei_xing+ "%' ";
        }
        if (shi_jian != "") {
            sql += "and shi_jian like '%" +shi_jian+ "%' ";
        }
        if (di_dian != "") {
            sql += "and di_dian like '%" +di_dian+ "%' ";
        }
        if(zhu_ti==""&& lei_xing==""&& shi_jian==""&& di_dian=="")
        {
            sql = "select * from active";
        }
        Statement state = null;
        state = connection.createStatement();
        ResultSet rs = state.executeQuery(sql);
        Active active = null;
        List<Active> list = new ArrayList<>();
        int count = 0;
        while (rs.next()) {
          count++;
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return count;
    }
}

 

四、Sevlet

@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
    Service service = new Service();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String method =request.getParameter("method");

        if("add".equals(method))
        {
            try {
                add(request , response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if("getbyzhu_ti_del".equals(method))
        {
            try {
                getbyzhu_ti_del(request , response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else if ("del".equals(method)) {
            try {
                del(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("update".equals(method)) {
            try {
                update(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("sel".equals(method)) {
            try {
                sel(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else if ("getbyID".equals(method))
        {
            try {
                getbyID(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else if("getbyzhu_ti".equals(method))
        {
            try{
                getbyzhu_ti(request , response);
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        else if("cha_xun".equals(method))
        {
            try{
                cha_xun(request , response);
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }

    private void cha_xun(HttpServletRequest request, HttpServletResponse response)throws  Exception {
        request.setCharacterEncoding("utf-8");
        String zhu_ti = request.getParameter("zhu_ti");
        String lei_xing = request.getParameter("lei_xing");
        String shi_jian = request.getParameter("shi_jian");
        String di_dian =  request.getParameter("di_dian");
        List<Active> list = service.cha_xun(zhu_ti ,lei_xing,shi_jian,di_dian );
        int count = service.cha_xun_if(zhu_ti ,lei_xing,shi_jian,di_dian );
        if(count != 0)
        {
            request.setAttribute("message" , "查询成功");
            request.setAttribute("list" , list);
            request.getRequestDispatcher("sel.jsp").forward(request,response);
        }else{
            request.setAttribute("message" , "该活动不存在");
            request.getRequestDispatcher("cha_xun.jsp").forward(request,response);
        }
    }

    private void getbyzhu_ti_del(HttpServletRequest request, HttpServletResponse response) throws  Exception{
        request.setCharacterEncoding("utf-8");
        String zhu_ti = request.getParameter("zhu_ti");

        Active active = service.getbyzhu_ti(zhu_ti);
        int count = service.getbyzhu_ti_if(zhu_ti);
        if(count != 0)
        {
            request.setAttribute("message" , "查询成功");
            request.setAttribute("active" , active);
            request.getRequestDispatcher("del.jsp").forward(request,response);
        }else{
            request.setAttribute("message" , "该活动不存在");
            request.getRequestDispatcher("getbyzhu_ti_del.jsp").forward(request,response);
        }
    }

    private void getbyzhu_ti(HttpServletRequest request, HttpServletResponse response) throws  Exception{
        request.setCharacterEncoding("utf-8");
        String zhu_ti = request.getParameter("zhu_ti");

        Active active = service.getbyzhu_ti(zhu_ti);
        int count = service.getbyzhu_ti_if(zhu_ti);
        if(count != 0)
        {
            request.setAttribute("message" , "查询成功");
            request.setAttribute("active" , active);
            request.getRequestDispatcher("update.jsp").forward(request,response);
        }else{
            request.setAttribute("message" , "该活动不存在");
            request.getRequestDispatcher("getbyzhu_ti.jsp").forward(request,response);
        }

    }

    private void getbyID(HttpServletRequest request, HttpServletResponse response) throws  Exception {
        request.setCharacterEncoding("utf-8");
        int ID = Integer.parseInt( request.getParameter("id"));
        Active active = service.getbyID(ID);

        request.setAttribute("active",active);
        request.getRequestDispatcher("update.jsp").forward(request,response);
    }

    private void sel(HttpServletRequest request, HttpServletResponse response) throws  Exception {
        request.setCharacterEncoding("utf-8");
        List<Active> list = service.sel_all();
        request.setAttribute("list" , list);
        request.getRequestDispatcher("sel.jsp").forward(request,response);
    }

    private void update(HttpServletRequest request, HttpServletResponse response)  throws  Exception{
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        int id = Integer.parseInt( request.getParameter("id"));
        String zhu_ti =  request.getParameter("zhu_ti");
        String mu_di =  request.getParameter("mu_di");
        String  lei_xing = request.getParameter("lei_xing");
        String shi_jian = request.getParameter("shi_jian");
        String di_dian =  request.getParameter("di_dian");
        String nei_rong = request.getParameter("nei_rong");
        String an_pai =  request.getParameter("an_pai");
        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 dui_xiang=a1+a2;

        Active active = new Active(id,zhu_ti, mu_di, lei_xing, shi_jian,di_dian, dui_xiang,nei_rong, an_pai);

        if (service.update(active)) {
            request.setAttribute("message" , "修改成功");
        }else{
            request.setAttribute("message" , "修改失败");
        }
        request.getRequestDispatcher("Servlet?method=sel").forward(request,response);
    }

    private void del(HttpServletRequest request, HttpServletResponse response) throws  Exception {
        request.setCharacterEncoding("utf-8");
        int id = Integer.parseInt( request.getParameter("id"));

        if(service.del(id))
        {
            request.setAttribute("message" , "删除成功");
        }else{
            request.setAttribute("message" , "删除失败");
        }
        request.getRequestDispatcher("Servlet?method=sel").forward(request,response);
    }

    private void add(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String zhu_ti =  request.getParameter("zhu_ti");
        String mu_di =  request.getParameter("mu_di");
        String  lei_xing = request.getParameter("lei_xing");
        String shi_jian = request.getParameter("shi_jian");
        String di_dian =  request.getParameter("di_dian");
        String nei_rong = request.getParameter("nei_rong");
        String an_pai =  request.getParameter("an_pai");
        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 dui_xiang=a1+a2;

        Active active = new Active(zhu_ti, mu_di, lei_xing, shi_jian,di_dian, dui_xiang,nei_rong, an_pai);

        if (service.add(active)) {
            request.setAttribute("message" , "添加成功");
        }else{
            request.setAttribute("message" , "添加失败");
        }
        request.getRequestDispatcher("add.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

 

五、Service

public class Service {
    public boolean add(Active active) throws Exception {
        Dao dao = new Dao();
        boolean f = true;
        if(dao.add(active) == 0)
        {
            f = false;
        }
        return f;
    }

    public boolean del(int id) throws Exception {
        Dao dao = new Dao();
        boolean f = true;
        if(dao.del(id) == 0)
        {
            f = false;
        }
        return f;
    }

    public List<Active> sel_all() throws Exception {
        Dao dao = new Dao();
        return   dao.selectall()  ;
    }

    public Active getbyzhu_ti( String zhu_ti) throws Exception {
        Dao dao = new Dao();

        return dao.getbyzhu_ti(zhu_ti)  ;
    }

    public int getbyzhu_ti_if(String zhu_ti) throws Exception {
        Dao dao = new Dao();

        return   dao.getbyzhu_ti_if(zhu_ti)  ;
    }

    public boolean update(Active active) throws Exception {
        Dao dao = new Dao();
        boolean f = false;
        int count = dao.update(active);
        if(count != 0)
        {
            f = true;
        }
        return f;
    }

    public Active getbyID(int id) throws Exception {
        Dao dao = new Dao();
        Active active = dao.getbyID(id);
        return active;
    }

    public List<Active> cha_xun(String zhu_ti, String lei_xing, String shi_jian, String di_dian) throws Exception {
        Dao dao = new Dao();

        return dao.cha_xun(zhu_ti ,lei_xing,shi_jian,di_dian)  ;
    }

    public int cha_xun_if(String zhu_ti, String lei_xing, String shi_jian, String di_dian)throws Exception  {
        Dao dao = new Dao();

        return dao.cha_xun_if(zhu_ti ,lei_xing,shi_jian,di_dian)  ;
    }
}

 

六、JSP

(一)主界面

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/27
  Time: 23:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>校园社团活动管理系统</title>
</head>
<body>
<div align="center">

  <div class="a">
    <a href="add.jsp">发布活动信息</a>
  </div>
  <div class="a">
    <a href="getbyzhu_ti.jsp">修改活动信息</a>
  </div>
  <div class="a">
    <a href="getbyzhu_ti_del.jsp">删除活动信息</a>
  </div>
  <div class="a">
    <a href="cha_xun.jsp">查询活动信息</a>
  </div>
  <div class="a">
    <a href="Servlet?method=sel">信息浏览</a>
  </div>
</div>
</body>
</html>

(二)添加

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/27
  Time: 23:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8" >
    <title>发布活动信息</title>
</head>

<body>
<%
    Object message = request.getAttribute("message");
    if(message!=null && !"".equals(message)){

%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
    <h1 style="color: black;">发布活动信息</h1>

    <form name="form1" action="Servlet?method=add" method="post" onsubmit="return check()">
        <table align="center" border="1" width="1000">
            <tr>
                <td>活动主题 (不超过20个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="zhu_ti"  />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动目的 (不超过50个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="mu_di" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动类型 </td>
                <td>
                    <label>
                        <input type="radio" name="lei_xing" value="社团竞赛"checked>社团竞赛
                        <input type="radio" name="lei_xing" value="野外采风">野外采风
                        <input type="radio" name="lei_xing" value="校内集会">校内集会
                        <input type="radio" name="lei_xing" value="社团纳新">社团纳新
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动时间 </td>
                <td>
                    <label>
                        <input type="text" name="shi_jian" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动地点 </td>
                <td>
                    <label>
                        <input type="text" name="di_dian" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动对象</td>
                <td>
                    <label>
                        <input type="checkbox" name="a1"  value="社团成员" />社团成员
                        <input type="checkbox" name="a2"  value="全体学生" />全体学生
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动内容 (不超过500个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="nei_rong" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动日程安排 (不超过500个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="an_pai" />
                    </label>
                </td>
            </tr>
            <tr align="center">
                <td colspan="3">
                    <input type="submit" value="提交" />
                    <input type="reset" value="重置" />
                    <a href="index.jsp">返回主页</a>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    function check(){
        var zhu_ti = document.form1.zhu_ti.value;
        var mu_di = document.form1.mu_di.value;
        var nei_rong = document.form1.nei_rong.value;
        var an_pai = document.form1.an_pai.value;

        //非空
        if( zhu_ti.length > 20) {
            alert('活动主题超出规定长度');
            // name.focus();
            return false;
        }
        if( mu_di.length > 50) {
            alert('活动目的超出规定长度');
            // idc.focus();
            return false;
        }
        if(nei_rong.length > 500) {
            alert('活动内容超出规定长度');
            // type.focus();
            return false;
        }
        if(an_pai.length > 500) {
            alert('活动安排超出规定长度');
            //  department.focus();
            return false;
        }
    }

</script>
</body>
</html>

(三)删除

查询信息页面

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/28
  Time: 14:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除活动信息</title>
</head>
<body>
<%
    Object message = request.getAttribute("message");
    if(message != null && !"".equals(message)){
%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%}%>
<div align="center">
    <form name="form2" action="Servlet?method=getbyzhu_ti_del" method="post" onsubmit="return check()">
        <table align="center">
            请输入活动主题:<input type="text" name="zhu_ti" /><br>
            <input type="submit" value="查询" />
        </table>
    </form>
</div>
<script type="text/javascript" >
    function check()
    {
        var zhu_ti= document.form2.zhu_ti.value;

        if (zhu_ti == '')
        {
            alert('活动主题为空');
            return false;
        }
    }
</script>
</body>
</html>


//删除详情页面

<%-- Created by IntelliJ IDEA. User: wanghongbing Date: 2022/10/28 Time: 14:54 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>删除活动信息页面</title> </head> <body> <% Object message = request.getAttribute("message"); if(message != null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%}%> <div align="center"> <h1 style="color: black;">信息列表</h1> <table border="1px"> <tr> <td>活动主题</td> <td>活动目的</td> <td>活动类型</td> <td>活动时间</td> <td>活动地点</td> <td>活动对象</td> <td>活动内容</td> <td>活动日程安排</td> </tr> <tr> <td>${requestScope.active.zhu_ti}</td> <td>${requestScope.active.mu_di}</td> <td>${requestScope.active.lei_xing}</td> <td>${requestScope.active.shi_jian}</td> <td>${requestScope.active.di_dian}</td> <td>${requestScope.active.dui_xiang}</td> <td>${requestScope.active.nei_rong}</td> <td>${requestScope.active.an_pai}</td> <td><a onclick="return check()" href="Servlet?method=del&&id=${requestScope.active.id}">删除</a></td> <td><a href="index.jsp">返回主页</a></td> </tr> </table> </div> <script type="text/javascript"> function check() { if (confirm("是否确认删除该活动信息")){ return true; }else{ return false; } } </script> </body> </html>

(四)修改

查询信息页面

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/28
  Time: 14:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改活动信息</title>
</head>
<body>
<%
    Object message = request.getAttribute("message");
    if(message != null && !"".equals(message)){
%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%}%>
<div align="center">
    <form name="form2" action="Servlet?method=getbyzhu_ti" method="post" onsubmit="return check()">
        <table align="center">
            请输入活动主题:<input type="text" name="zhu_ti" /><br>
            <input type="submit" value="查询" />
        </table>
    </form>
</div>
<script type="text/javascript" >
    function check()
    {
        var zhu_ti= document.form2.zhu_ti.value;

        if (zhu_ti == '')
        {
            alert('活动主题为空');
            return false;
        }
    }
</script>
</body>
</html>

 修改信息详情页面

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/28
  Time: 15:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改活动信息</title>
</head>
<body>
<%
    Object message = request.getAttribute("message");
    if(message!=null && !"".equals(message)){

%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
    <h1 style="color: black;">修改活动信息</h1>

    <form name="form1" action="Servlet?method=update&&id=${requestScope.active.id}" method="post" onsubmit="return check()">
        <table align="center" border="1" width="500">
            <tr>
                <td>活动主题 (不超过20个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="zhu_ti" value="${requestScope.active.zhu_ti}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动目的 (不超过50个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="mu_di" value="${requestScope.active.mu_di}" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动类型 </td>
                <td>
                    <label>
                        <input type="radio" name="lei_xing" value="社团竞赛" checked>社团竞赛
                        <input type="radio" name="lei_xing" value="野外采风">野外采风
                        <input type="radio" name="lei_xing" value="校内集会">校内集会
                        <input type="radio" name="lei_xing" value="社团纳新">社团纳新
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动时间 =</td>
                <td>
                    <label>
                        <input type="text" name="shi_jian" value="${requestScope.active.shi_jian}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动地点 </td>
                <td>
                    <label>
                        <input type="text" name="di_dian" value="${requestScope.active.di_dian}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动对象 </td>
                <td>
                    <label>
                        <input type="checkbox" name="a1"  value="社团成员" />社团成员
                        <input type="checkbox" name="a2"  value="全体学生" checked="checked"/>全体学生
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动内容 (不超过500个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="nei_rong" value="${requestScope.active.nei_rong}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>活动日程安排 (不超过500个汉字)</td>
                <td>
                    <label>
                        <input type="text" name="an_pai" value="${requestScope.active.an_pai}"/>
                    </label>
                </td>
            </tr>
            <tr align="center">
                <td colspan="3">
                    <input type="submit" value="提交" />
                    <input type="reset" value="重置" />
                    <a href="index.jsp">返回主页</a>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    function check(){
        var zhu_ti = document.form1.zhu_ti.value;
        var mu_di = document.form1.mu_di.value;
        var nei_rong = document.form1.nei_rong.value;
        var an_pai = document.form1.an_pai.value;

        //非空
        if( console.log(zhu_ti.length) > 20) {
            alert('活动主题超出规定长度');
            // name.focus();
            return false;
        }
        if( console.log(mu_di.length) > 50) {
            alert('活动目的超出规定长度');
            // idc.focus();
            return false;
        }
        if(console.log(nei_rong.length) > 500) {
            alert('活动内容超出规定长度');
            // type.focus();
            return false;
        }
        if(console.log(an_pai.length) > 500) {
            alert('活动安排超出规定长度');
            //  department.focus();
            return false;
        }
    }

</script>
</body>
</html>

(五)查询

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/28
  Time: 15:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询活动信息</title>
</head>
<body>
<%
    Object message = request.getAttribute("message");
    if(message != null && !"".equals(message)){
%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%}%>
<div align="center">
    <form name="form3" action="Servlet?method=cha_xun" method="post" >
        <table align="center">
            请输入活动主题:<input type="text" name="zhu_ti" /><br>
            请输入活动时间:<input type="text" name="shi_jian" /><br>
            请输入活动类型:<input type="text" name="lei_xing" /><br>
            请输入活动地点:<input type="text" name="di_dian" /><br>
            <input type="submit" value="查询" />
        </table>
    </form>
</div>
</body>
</html>

(六)浏览

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/27
  Time: 23:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>活动信息浏览</title>
</head>
<body>
<%
    Object message = request.getAttribute("message");
    if(message != null && !"".equals(message)){
%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%}%>

<div align="center">
    <h1 style="color: black;">信息列表</h1>
    <table border="1px">
        <tr>
            <td>活动主题</td>
            <td>活动类型</td>
            <td>活动时间</td>
            <td>活动对象</td>
        </tr>
        <c:forEach items="${list}" var="item">
            <tr>
                <td><a href="Servlet?method=getbyzhu_ti_del&&zhu_ti=${item.zhu_ti}">${item.zhu_ti}</a></td>
                <td>${item.lei_xing}</td>
                <td>${item.shi_jian}</td>
                <td>${item.dui_xiang}</td>
                <td> <a href="index.jsp">返回主页</a></td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>
</html>

 

标签:zhu,String,管理系统,期中考试,di,request,社团活动,ti,active
From: https://www.cnblogs.com/fan-wang/p/16847014.html

相关文章