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

校园社团活动管理系统

时间:2022-11-04 16:22:33浏览次数:62  
标签:String rs request 管理系统 校园 zhuti 社团活动 import 活动

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

 

所有的.java和.jsp文件如下

 

Bean.java

 

package bean;

public class Bean {
    private int id;
    private String zhuti;
    private String mudi;
    private String leixing;
    private String time ;
    private String place;
    private String duixiang;
    private String neirong;
    private String 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 getLeixing() {
        return leixing;
    }

    public void setLeixing(String leixing) {
        this.leixing = leixing;
    }

    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;
    }
    public Bean() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Bean(int id, String zhuti, String mudi, String leixing, String time, String place, String duixiang, String neirong, String anpai) {
        super();
        this.id = id;
        this.zhuti = zhuti;
        this.mudi = mudi;
        this.leixing = leixing;
        this.time = time;
        this.place = place;
        this.duixiang = duixiang;
        this.neirong = neirong;
        this.anpai = anpai;
    }
    public Bean( String zhuti, String mudi, String leixing, String time, String place, String duixiang, String neirong, String anpai) {
        super();

        this.zhuti = zhuti;
        this.mudi = mudi;
        this.leixing = leixing;
        this.time = time;
        this.place = place;
        this.duixiang = duixiang;
        this.neirong = neirong;
        this.anpai = anpai;
    }
}

 

Dao.java

package dao;

import Util.DBUtil;
import bean.Bean;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Dao {
    public boolean add(Bean ten) throws ClassNotFoundException , SQLException
    {
        String sql="insert into person(zhuti,mudi,leixing,time,place,duixiang,neirong,anpai)values"
                + "('" + ten.getZhuti() + "','" + ten.getMudi() + "','"+ ten.getLeixing() + "','" + ten.getTime() + "','" + ten.getPlace() + "','" + ten.getDuixiang() + "','" + ten.getNeirong() + "','" + ten.getAnpai()+ "')";

        Connection conn= DBUtil.getConnection();
        Statement state=null;
        boolean f=false;
        int a = 0;
        try {
            state = conn.createStatement();
            state.executeUpdate(sql);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {

            DBUtil.close(state, conn);
        }
        if(a>0)
            f=true;
        return f;
    }

    public Bean getbyzhuti(String name) throws ClassNotFoundException ,SQLException
    {
        String sql = "select * from shetuan where zhuti ='" + name + "'";
        Connection conn = DBUtil.getConnection();
        Statement state = null;
        ResultSet rs = null;
        Bean ten = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                int id=rs.getInt("id");

                String zhuti2 = rs.getString("zhuti");
                String mudi2 = rs.getString("mudi");
                String leixing2 = rs.getString("leixing");
                String time2=rs.getString("time");
                String place2 = rs.getString("place");
                String duixiang2 =rs.getString("duixiang");
                String neirong2=rs.getString("neirong");
                String anpai2=rs.getString("anpai");

                ten = new Bean(id,zhuti2, mudi2,leixing2,time2,place2, duixiang2, neirong2, anpai2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return ten;
    }


    //delete
    public boolean delete(String name) throws SQLException, ClassNotFoundException {
        String sql="delete from shetuan where zhuti='" + name + "'";
        Connection conn = DBUtil.getConnection();
        Statement state = null;
        int a = 0;
        boolean f = false;
        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }
    //update
    public boolean update(Bean b)
    {
        Connection con=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        try {
            con=DBUtil.getConnection();
            String sql="update shetuan set zhuti=?,mudi=?,leixing=?,time=?,place=?,duixiang=?,neirong=?,anpai=? where id=?";
            pstmt=con.prepareStatement(sql);
            pstmt.setString(1, b.getZhuti());
            pstmt.setString(2, b.getMudi());
            pstmt.setString(3, b.getLeixing());
            pstmt.setString(4, b.getTime());
            pstmt.setString(5, b.getPlace());
            pstmt.setString(6, b.getDuixiang());
            pstmt.setString(7, b.getNeirong());
            pstmt.setString(7, b.getAnpai());
            pstmt.setInt(8, b.getId());
            pstmt.executeUpdate();
            return true;
        }
        catch (SQLException | ClassNotFoundException e) {
            System.out.println("更新失败");
            e.printStackTrace();
        }
        finally {
            DBUtil.close(rs, pstmt, con);
        }
        return false;
    }
    //查找
    public boolean name(String name) throws SQLException, ClassNotFoundException {
        boolean flag = false;
        String sql = "select zhuti from shetuan where zhuti = '" + name + "'";
        Connection conn = DBUtil.getConnection();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }
        return flag;
    }


    public List<Bean> search(String zhuti, String time, String leixing, String place) throws SQLException, ClassNotFoundException {
        String sql = "select * from shetuan where ";


        if (zhuti != "") {
            sql += "zhuti like '%" +zhuti+ "%'";
        }

        if (time != "") {
            sql += "time like '%" +time+ "%'";
        }
        if(leixing!="") {
            sql+="leixing like '%"+leixing+ "%'";
        }

        if(place!="") {
            sql+="place like '%" +place+ "%'";
        }
        List<Bean> list = new ArrayList<>();
        Connection conn = DBUtil.getConnection();
        Statement state = null;
        ResultSet rs = null;
        Bean bean = null;
        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                String zhuti2 = rs.getString("zhuti");
                String mudi2 = rs.getString("mudi");
                String leixing2 = rs.getString("leixing");
                String time2=rs.getString("time");
                String place2 = rs.getString("place");
                String duixiang2 =rs.getString("duixiang");
                String neirong2=rs.getString("neirong");
                String anpai2=rs.getString("anpai");

                bean = new Bean(zhuti2, mudi2,leixing2,time2,place2, duixiang2, neirong2, anpai2);

                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }

    public List<Bean> list() throws SQLException, ClassNotFoundException {
        String sql = "select * from shetuan";
        List<Bean> list = new ArrayList<>();
        Connection conn = DBUtil.getConnection();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                Bean bean = null;
                int id=rs.getInt("id");
                String zhuti2 = rs.getString("zhuti");
                String mudi2 = rs.getString("mudi");
                String leixing2 = rs.getString("leixing");
                String time2=rs.getString("time");
                String place2 = rs.getString("place");
                String duixiang2 =rs.getString("duixiang");
                String neirong2=rs.getString("neirong");
                String anpai2=rs.getString("anpai");

                bean = new Bean(id,zhuti2, mudi2,leixing2,time2,place2, duixiang2, neirong2, anpai2);

                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }
}

Service.java

package service;

import bean.Bean;
import dao.Dao;

import java.sql.SQLException;
import java.util.List;

public class Service {
    Dao tDao=new Dao();
    public boolean add(Bean ten) throws SQLException, ClassNotFoundException {
        boolean f = false;
        if(!tDao.name(ten.getZhuti()))
        {
            tDao.add(ten);
            f=true;
        }
        return f;
    }

    public boolean del(String zhuti) throws SQLException, ClassNotFoundException {
        tDao.delete(zhuti);
        return true;
    }

    public boolean update(Bean ten)
    {
        tDao.update(ten);
        return true;
    }

    public Bean getbyzhuti(String zhuti) throws SQLException, ClassNotFoundException {
        return tDao.getbyzhuti(zhuti);
    }

    public List<Bean> search(String zhuti, String time, String leixing, String place) throws SQLException, ClassNotFoundException {
        return tDao.search(zhuti,time,leixing,place);
    }


    public List<Bean> list() throws SQLException, ClassNotFoundException {
        return tDao.list();
    }
}

DBUtil.java

package util;

import java.sql.*;

public class DBUtil {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {

        Connection connection = null;//连接数据库
        Statement stmt = null;//Statement 对象用于将 SQL 语句发送到数据库中。
        ResultSet rs = null;
        //1. 导入驱动jar包
        //2.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
//        好像要设置时区??
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/CLASS ?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT", "root", "123456");

        return connection;
    }

    public static void close(Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void close(PreparedStatement preparedStatement) {
        try {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void close(ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }




    public static void close(Statement state, Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }
            if (state != null)
            {
                state.close();
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void close(ResultSet rs, Statement state, Connection conn) {
        try {
            if (conn != null) {
                conn.close();
            }
            if (state != null)
            {
                state.close();
            }
            if(rs != null)
            {
                rs.close();
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

index.jsp  主界面

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="ISO-8859-1">
  <title>校园社团活动管理系统</title>
</head>
<body>
<p align="center"><font size="30" color="red">校园社团活动管理系统</font></p>
<center>
  <hr>
  <form name="form" action="Add.jsp">
    <b>发布活动信息</b>
    <input type="submit" value="进入">
  </form>
  <br>
  <form name="form1" action="Update.jsp">
    <b>修改活动信息</b>
    <input type="submit" value="进入">
  </form>
  <br>
  <form name="form2" action="Delete.jsp">
    <b>删除活动信息</b>
    <input type="submit" value="进入">
  </form>
  <br>
  <form name="form3" action="Chaxun.jsp">
    <b>查询活动信息</b>
    <input type="submit" value="进入">
  </form>
  <br>
  <form name="form4" action="zongliulan.jsp">
    <b>浏览活动信息</b>
    <input type="submit" value="进入">
  </form>
  <br>
</center>
</body>
</html>

Add.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>活动信息登记</title>
</head>
<body>
<form method="post"  action="addServlet">
    <table align="center" border="1" width="600">
        <tr>
            <td>活动主题</td>
            <td>
                <input type="text" name="zhuti" ><br>
            </td>
        </tr>
        <tr>
            <td>活动目的</td>
            <td>
                <input type="text" name="mudi" ><br>
            </td>
        </tr>
        <tr>
            <td>活动类型</td>
            <%--            单选框--%>
            <td>
                <select name="leixing">
                    <option  value="社团竞赛">社团竞赛</option>
                    <option  value="野外采风">野外采风</option>
                    <option  value="校内集会">校内集会</option>
                    <option  value="社团纳新">社团纳新</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>活动时间</td>
            <td>
                <input type="text" name="time" ><br>
            </td>
        </tr>
        <tr>
            <td>活动地点</td>
            <td>
                <input type="text" name="place" ><br>
            </td>
        </tr>
        <tr>
            <td>活动对象</td>
            <td>
                <select name="duixiang">
                    <option value="社团成员">社团成员</option>
                    <option value="全体学生">全体学生</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>活动内容</td>
            <td>
                <input type="text" name="neirong" ><br>
            </td>
        </tr>
        <tr>
            <td>活动日程安排</td>
            <td>
                <input type="text" name="anpai"><br>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <button>提交</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

addServlet.java

package servlet;

import Util.DBUtil;
import service.Service;

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;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@WebServlet("/addServlet")
public class addServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    Service service = new Service();


    @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 mudi = request.getParameter("mudi");
        String leixing = request.getParameter("leixing");
        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");

        PrintWriter write = response.getWriter();

            PreparedStatement preparedStatement = null;
            Connection connection = null;
            try {
                connection = DBUtil.getConnection();
                String sql = "insert into shetuan(zhuti,mudi,leixing,time,place,duixiang,neirong,anpai) values(?,?,?,?,?,?,?,?)";
                preparedStatement = null;
                preparedStatement = connection.prepareStatement(sql);
                preparedStatement.setString(1, zhuti);
                preparedStatement.setString(2, mudi);
                preparedStatement.setString(3, leixing);
                preparedStatement.setString(4, time);
                preparedStatement.setString(5, place);
                preparedStatement.setString(6, duixiang);
                preparedStatement.setString(7, neirong);
                preparedStatement.setString(8, anpai);
                preparedStatement.executeUpdate();
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                DBUtil.close(preparedStatement);
                DBUtil.close(connection);
            }
            request.getRequestDispatcher("liulan.jsp").forward(request,response);
        }


    private boolean isNumeric(String str) {
        for (int i = str.length();--i>=0;){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }
}

liulan.jsp    登记以后可以浏览信息

<%@ page import="Util.DBUtil" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ 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>

<h2 align="center" >操作成功</h2><br>
<table align="center"  border="1">
    <tr>
        <td align="center" width=10%>活动主题</td>
        <td align="center" width=10%>活动目的</td>
        <td align="center" width=10%>活动类型</td>
        <td align="center" width=10%>活动时间</td>
        <td align="center" width=10%>活动地点</td>
        <td align="center" width=10%>活动对象</td>
        <td align="center" width=10%>活动内容</td>
        <td align="center" width=10%>活动日程安排</td>

    </tr>

    <%

        Connection connection= DBUtil.getConnection();
        PreparedStatement preparedStatement=null;
        ResultSet in=null;
        try{
//        按照添加时间排序::
            preparedStatement=connection.prepareStatement("select * from shetuan");
            in = preparedStatement.executeQuery();
            while(in.next()){
    %>
    <tr>
        <td><%=in.getString(1)%></td>
        <td><%=in.getString(2)%></td>
        <td><%=in.getString(3)%></td>
        <td><%=in.getString(4)%></td>
        <td><%=in.getString(5)%></td>
        <td><%=in.getString(6)%></td>
        <td><%=in.getString(7)%></td>
        <td><%=in.getString(8)%></td>

    </tr>
    <%
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            connection.close();
            preparedStatement.close();
            in.close();
        }
    %>
    <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
        <br> <input type="button" value="返回菜单" onclick="location.href='index.jsp'" /> <br>
</table>
</body>
</html>

Update.jsp   

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

xiugaiServlet.java

package servlet;
import Util.DBUtil;

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;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@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");
        //获取jsp 中的 name
        String zhuti = request.getParameter("zhuti");
        //链接
        try {
            Connection connection = DBUtil.getConnection();
            String sql = "select * from shetuan where zhuti=?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, zhuti);
            ResultSet rs = preparedStatement.executeQuery();
            int i = 0;
            if (rs.next()) {
                i = 1;
                request.setAttribute("zhuti", rs.getString("zhuti"));
                request.setAttribute("mudi", rs.getString("mudi"));
                request.setAttribute("leixing", rs.getString("leixing"));
                request.setAttribute("time", rs.getString("time"));
                request.setAttribute("place", rs.getString("place"));
                request.setAttribute("duixiang", rs.getString("duixiang"));
                request.setAttribute("neirong", rs.getString("neirong"));
                request.setAttribute("anpai", rs.getString("anpai"));

                rs.close();
                preparedStatement.close();
                connection.close();
            }
            if(i==1){
                request.getRequestDispatcher("Update02.jsp").forward(request,response);
            }
            else{
                PrintWriter write= response.getWriter();
                write.write("该社团活动信息不存在");
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}

Update02.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>修改页面户主信息显示</title>
</head>
<body>
<%
  String zhuti = (String) request.getAttribute("zhuti");
  session.setAttribute("zhuti",zhuti);
%>
<form method="post" action="xiugaiServlet02">
  <table align="center" border="1">
    <tr>
      <td>活动主题</td>
      <td>${zhuti}</td>
      <td>修改:
        <input type="text" name="zhuti" ><br>
      </td>
    </tr>
    <tr>
      <td>活动目的</td>
      <td>${mudi}</td>
      <td>修改:
        <input type="text" name="mudi" ><br>
      </td>
    </tr>
    <tr>
      <td>活动类型:</td>
      <td>${类型}</td>
      <td>
        修改:
        <select name="leixing">
          <option value="社团竞赛">社团竞赛</option>
          <option value="野外采风">野外采风</option>
          <option value="校内集会">校内集会</option>
          <option value="社团纳新">社团纳新</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>活动时间</td>
      <td>${time}</td>
      <td>修改:
        <input type="text" name="time" ><br>
      </td>
    </tr>
    <tr>
      <td>活动地点</td>
      <td>${place}</td>
      <td>修改:
        <input type="text" name="place" ><br>
      </td>
    </tr>
    <tr>
      <td>活动对象</td>
      <td>${duixiang}</td>
      <td>修改:
        <select name="duixiang">
          <option value="全体学生">全体学生</option>
          <option value="社团成员">社团成员</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>活动内容</td>
      <td>${neirong}</td>
      <td>修改:
        <input type="text" name="neirong" ><br>
      </td>
    </tr>
    <tr>
      <td>活动日程安排</td>
      <td>${anpai}</td>
      <td>修改:
        <input type="text" name="anpai"><br>
      </td>
    </tr>

    <tr align="center">
      <td colspan="3"><button>保存信息</button></td>
      <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
        <br> <input type="button" value="返回菜单" onclick="location.href='index.jsp'" /> <br>
    </tr>
  </table>
</form>
</body>
</html>

xiugaiServlet02.java

package servlet;

import Util.DBUtil;

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;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/xiugaiServlet02")
public class xiugaiServlet02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //从jsp接收数据
//        String name = request.getParameter("name");
//        System.out.println(name);
        String zhuti = (String) request.getSession().getAttribute("zhuti");
        System.out.println(zhuti);
        String mudi= request.getParameter("mudi");
        String leixing = request.getParameter("leixing");
        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");

        PrintWriter writer=response.getWriter();
        //连接
        try {
            Connection connection = DBUtil.getConnection();
            String sql="update shetuan set mudi=?,leixing=?,time=?,place=?,duixiang=?,neirong=? ,anpai=? where zhuti=?";
            PreparedStatement preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setString(8,zhuti);
            preparedStatement.setString(1,mudi);
            preparedStatement.setString(2,leixing);
            preparedStatement.setString(3,time);
            preparedStatement.setString(4,place);
            preparedStatement.setString(5,duixiang);
            preparedStatement.setString(6,neirong);
            preparedStatement.setString(7,anpai);

            int rs=preparedStatement.executeUpdate();
            if(rs>0){
                writer.write("修改成功");
                request.getRequestDispatcher("liulan.jsp").forward(request,response);
            }
            else{
                writer.write("修改失败");
            }
            preparedStatement.close();
            connection.close();
            writer.close();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

Delete.jsp

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

deleteServlet.java

package servlet;
import Util.DBUtil;


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;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/deleteServlet")
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");
        PrintWriter writer = response.getWriter();
        try {
            Connection connection= DBUtil.getConnection();
            String sql = "delete from shetuan where zhuti=?";
            PreparedStatement preparedStatement=connection.prepareStatement(sql);
            //对应问号
            preparedStatement.setString(1,zhuti);
            int rs = preparedStatement.executeUpdate();
            if(rs>0){
//                System.out.println("删除成功");
                writer.write("删除成功");
                request.getRequestDispatcher("liulan.jsp").forward(request,response);
            }else{
//                System.out.println("删除失败");
                writer.write("删除失败");
            }
            preparedStatement.close();
            connection.close();
            writer.close();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}

Chaxun.jsp

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

</form>
</body>
</html>

chaxunServlet.java

package servlet;

import Util.DBUtil;

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;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@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 leixing=request.getParameter("leixing");
        String place=request.getParameter("place");
        //连接
        try {
            Connection connection = DBUtil.getConnection();
            String sql = "select * from shetuan where zhuti like ? ";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,"%"+zhuti+"%");
            ResultSet rs= preparedStatement.executeQuery();
            while(rs.next()){
                request.setAttribute("zhuti",rs.getString("zhuti"));
                request.setAttribute("mudi",rs.getString("mudi"));
                request.setAttribute("leixing",rs.getString("leixing"));
                request.setAttribute("time",rs.getString("time"));
                request.setAttribute("place",rs.getString("place"));
                request.setAttribute("duixiang",rs.getString("duixiang"));
                request.setAttribute("neirong",rs.getString("neirong"));
                request.setAttribute("anpai",rs.getString("anpai"));

                request.getRequestDispatcher("Chaxun02.jsp").forward(request,response);
                rs.close();
                preparedStatement.close();
                connection.close();
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }



    }
}

Chaxun02.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询结果</title>
</head>
<body>
<table align="center"  border="1">
    <tr>
        <td>活动主题</td>
        <td>活动目的</td>
        <td>活动类型</td>
        <td>活动时间</td>
        <td>活动地点</td>
        <td>活动对象</td>
        <td>活动内容</td>
        <td>活动日程安排</td>

    </tr>
    <tr>
        <td>${zhuti}</td>
        <td>${mudi}</td>
        <td>${leixing}</td>
        <td>${time}</td>
        <td>${place}</td>
        <td>${duixiang}</td>
        <td>${neirong}</td>
        <td>${anpai}</td>

    </tr>
</table>
</body>
</html>

zongliulan.jsp

<%@ page import="java.sql.Connection" %>
<%@ page import="Util.DBUtil" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览页面</title>
</head>
<body>
<table align="center"  border="1">
    <tr>
        <td align="center" width=10%>活动主题</td>
        <td align="center" width=10%>活动目的</td>
        <td align="center" width=10%>活动类型</td>
        <td align="center" width=10%>活动时间</td>
        <td align="center" width=10%>活动地点</td>
        <td align="center" width=10%>活动对象</td>
        <td align="center" width=10%>活动内容</td>
        <td align="center" width=10%>活动日程安排</td>

    </tr>


        <%
    //浏览
    //链接
//    Connection connection = null;
//    //数据库操作对象
//    PreparedStatement preparedStatement=null;
//    //查询结果
//    ResultSet resultSet=null;
//
    Connection connection= DBUtil.getConnection();
    PreparedStatement preparedStatement=null;
    ResultSet in=null;
    try{
//        按照添加时间排序::
        preparedStatement=connection.prepareStatement("select * from shetuan");
        in = preparedStatement.executeQuery();
        while(in.next()){
%>
    <tr>
        <td><%=in.getString(1)%></td>
        <td><%=in.getString(2)%></td>
        <td><%=in.getString(3)%></td>
        <td><%=in.getString(4)%></td>
        <td><%=in.getString(5)%></td>
        <td><%=in.getString(6)%></td>
        <td><%=in.getString(7)%></td>
        <td><%=in.getString(8)%></td>

    </tr>
        <%
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }finally {
        connection.close();
        preparedStatement.close();
        in.close();
        }
%>
</body>
</html>

 

目前查询那部分还有问题,只能输入活动主题后,查询出来的结果是正确的,其他输入活动主题,类型,地点都还有点问题,不能够实现模糊查询,后面还得再改改,改完以后再发一篇博客

 

标签:String,rs,request,管理系统,校园,zhuti,社团活动,import,活动
From: https://www.cnblogs.com/psh888/p/16858226.html

相关文章