校园社团活动管理系统java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package Bean;
 
public class Bean1 {
    private String zhuti;
    private String mudi;
    private String leixing;
    private String shijian;
    private String didian;
    private String duixiang;
    private String neirong;
    private String anpai;
     
     
     
    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 getShijian() {
        return shijian;
    }
 
    public void setShijian(String shijian) {
        this.shijian = shijian;
    }
 
    public String getDidian() {
        return didian;
    }
 
    public void setDidian(String didian) {
        this.didian = didian;
    }
 
    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;
    }
 
    /*@Override
    public String toString() {
        return "Bean1 [zhuti=" + zhuti + ", mudi=" + mudi + ", leixing=" + leixing + ", shijian=" + shijian
                + ", didian=" + didian + ", duixiang=" + duixiang + ", neirong=" + neirong + ", anpai=" + anpai
                + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
                + "]";
    }*/
 
    public Bean1(String zhuti, String mudi, String leixing, String shijian, String didian, String duixiang, String neirong, String anpai) {
        this.zhuti=zhuti;
        this.mudi=mudi;
        this.leixing=leixing;
        this.shijian=shijian;
        this.didian=didian;
        this.duixiang=duixiang;
        this.neirong=neirong;
        this.anpai=anpai;
         
         
         
        //super();
        // TODO Auto-generated constructor stub
    }
     
     
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package Dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
 
import Bean.Bean1;
import Util.Util1;
 
 
 
public class Dao1 {
    public static int add(Bean1 bean)
    {
            String sql = "insert into 校园社团活动管理系统(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai) values('" +bean.getZhuti() + "','" + bean.getMudi() + "','" +bean.getLeixing() + "','"+bean.getShijian() + "','"+bean.getDidian() + "','"+bean.getDuixiang() + "','"+ bean.getNeirong() + "','" +bean.getAnpai()+"')";
            Connection conn = Util1.getConn();
            Statement state = null;
             int count=0;
             try {
                 state = conn.createStatement();
                 count = state.executeUpdate(sql);
                 } catch (Exception e) {
                 e.printStackTrace();
                 } finally {
                 //关闭连接
                 Util1.close(state, conn);
                 }
             return count;
    }
     
    public static int update(Bean1 bean)
    {
         
         
        String sql = "update 校园社团活动管理系统 set mudi='" + bean.getMudi() + "', leixing='" + bean.getLeixing() +"', shijian='" + bean.getShijian() +"', didian='" + bean.getDidian() +"', duixiang='" + bean.getDuixiang() +"', neirong='" + bean.getNeirong() + "', anpai='" + bean.getAnpai()
        + "' where zhuti='" + bean.getZhuti() + "'";
 
        Connection conn = Util1.getConn();
         
        Statement state = null;
        int count=0;
         try {
             state = conn.createStatement();
             count = state.executeUpdate(sql);
             } catch (Exception e) {
             e.printStackTrace();
             } finally {
             //关闭连接
             Util1.close(state, conn);
             }
         return count;
    }
     
    public static int delete (String t) {
        int count=0;
        String sql = "delete from 校园社团活动管理系统 where zhuti='" + t + "'";
        System.out.println(sql);
        Connection conn = Util1.getConn();
        Statement state = null;
        try {
        state = conn.createStatement();
        count = state.executeUpdate(sql);
        } catch (SQLException e) {
        e.printStackTrace();
        } finally {
        Util1.close(state, conn);
        }
        return count;
 
         
         
    }
 
     
 
}package Util;
import java.sql.*;
public class Util1 {
     
    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost:3306/demo?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
    static final String USER = "root";
    static final String PASS = "123456";
    public static Connection getConn () {
    Connection conn = null;
    try {
          Class.forName(JDBC_DRIVER);  
          System.out.println("连接数据库...");
          conn = DriverManager.getConnection(DB_URL,USER,PASS);
    } catch (Exception e) {
    e.printStackTrace();
    }
    return conn;
    }
     
public static void close (Statement state, Connection conn) {
         
        if (state != null) {
        try {
        state.close();
        } catch (SQLException e) {
        e.printStackTrace();
        }
        }
 
        if (conn != null) {
        try {
        conn.close();
        } catch (SQLException e) {
        e.printStackTrace();
        }
        }
        }
       public static void close (ResultSet rs, Statement state, Connection conn) {
                   if (rs != null) {
                           try {
                       rs.close();
                                } catch (SQLException e) {
                                e.printStackTrace();
                                 }
                                  }
 
                                if (state != null) {
                                 try {
                                 state.close();
                                 } catch (SQLException e) {
                                 e.printStackTrace();
                                 }
                                 }
 
                                if (conn != null) {
                                  try {
                             conn.close();
                             } catch (SQLException e) {
                             e.printStackTrace();
                           }
                          }
                           }
 
}
package servlet;
import java.sql.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
 
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Bean.Bean1;
import service.Service;
 
 
 
 
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
      Service service=new Service();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
     
        req.setCharacterEncoding("utf-8");
        String method = req.getParameter("method");
        if ("add".equals(method))
        {
            try {
                add(req, res);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }
        if ("update".equals(method))
        {
            try {
                update(req, res);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }
        if ("delete".equals(method))
        {
            try {
                delete(req, res);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }
    }
 
        private void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
            // TODO Auto-generated method stub
            req.setCharacterEncoding("utf-8");
            String zhuti = req.getParameter("zhuti");
            int i =service.delete(zhuti);
            if(i>0) {
                req.setAttribute("message", "删除成功!");
                req.getRequestDispatcher("shanchu.jsp").forward(req,resp);
                } else {
                    req.setAttribute("message", "删除失败!");
                req.getRequestDispatcher("shanchu.jsp").forward(req,resp);
                }
             
             
             
        }
     
 
    private void add(HttpServletRequest req, HttpServletResponse res) throws Exception {
        req.setCharacterEncoding("utf-8");
        String zhuti = req.getParameter("zhuti");
        String mudi = req.getParameter("mudi");
        String leixing = req.getParameter("leixing");
        String shijian = req.getParameter("shijian");
        String didian = req.getParameter("didian");
        String duixiang = req.getParameter("duixiang");
        String neirong = req.getParameter("neirong");
        String anpai = req.getParameter("anpai");
        //people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);
         Bean1 bean=new Bean1(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai);
        //添加后消息显示
        if(service.add(bean)>0) {
            req.setAttribute("message", "添加成功");
        req.getRequestDispatcher("add.jsp").forward(req,res);
        } else {
        req.setAttribute("message", "添加失败,请重新录入");
        req.getRequestDispatcher("add.jsp").forward(req,res);
        }
         
    }
    private void update(HttpServletRequest req, HttpServletResponse res) throws Exception {
        req.setCharacterEncoding("utf-8");
        String zhuti = req.getParameter("zhuti");
        String mudi = req.getParameter("mudi");
        String leixing = req.getParameter("leixing");
        String shijian = req.getParameter("shijian");
        String didian = req.getParameter("didian");
        String duixiang = req.getParameter("duixiang");
        String neirong = req.getParameter("neirong");
        String anpai = req.getParameter("anpai");
        //people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);
         Bean1 bean=new Bean1(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai);
        //添加后消息显示
        if(service.update(bean)>0) {
            req.setAttribute("message", "修改成功");
        req.getRequestDispatcher("xiugai.jsp").forward(req,res);
        } else {
        req.setAttribute("message", "修改失败,请重新录入");
        req.getRequestDispatcher("xiugai.jsp").forward(req,res);
        }
         
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
 
}
package service;
import Bean.Bean1;
import Dao.Dao1;
public class Service {
    public int add(Bean1 bean)
    {
        if(Dao1.add(bean)>0)
        {
            return 1;
        }
        else
        {
            return 0;
        }
         
         
         
    }
    public int update(Bean1 bean)
    {
        if(Dao1.update(bean)>0)
        {
            return 1;
        }
        else
        {
            return 0;
        }  
         
    }
     public int delete(String zhuti) {
            if(Dao1.delete(zhuti)>0)
            {
                return 1;
            }
            return 0;
        }
 
     
}

  

  

  

  

  Screen.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>校园社团活动管理系统</title>
</head>
<body>
<div align="center">
<form name="form" method="post" action="add.jsp">
                          <input type="submit" value="发布活动信息">
</form>
<form name="form" method="post" action="xiugai.jsp">
                          <input type="submit" value="修改活动信息">
</form>
<form name="form" method="post" action="shanchu.jsp">
                          <input type="submit" value="删除活动信息">
</form>
<form name="form" method="post" action="chaxun.jsp">
                          <input type="submit" value="查询活动信息">
</form>
<form name="form" method="post" action="liulan.jsp">
                          <input type="submit" value="活动信息浏览">
</form>
</div>
</body>
</html>

  

add.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<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>
<a href="Screen.jsp">返回主页</a>
<form name="form1" action="Servlet?method=add" method="post" onsubmit="return check()">
 
活动主题
<input type="text" name="zhuti"required pattern="^[\u4e00-\u9fa5]{1,20}"/>
<br>
活动目的
<input type="text" name="mudi"required pattern="^[\u4e00-\u9fa5]{1,50}"/><br>
活动类型
 
 <td>
            <input type="radio" name="leixing" value="社团竞赛" >社团竞赛
            <input type="radio" name="leixing" value="野外采风" >野外采风<br>
            <input type="radio" name="leixing" value="校内集会" >校内集会
            <input type="radio" name="leixing" value="社团纳新" >社团纳新
            </td><br>
活动时间
<input type="text" name="shijian"><br>
活动地点
<input type="text" name="didian"><br>
活动对象
 
 <tr>
                 
                <td>
 <input type="checkbox" name="duixiang" value="社团成员">社团成员
 <input type="checkbox" name="duixiang" value="全体学生">全体学生
 </td>
            </tr>
            <br>
活动内容
<input type="text" name="neirong"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
活动日程安排
<input type="text" name="anpai"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
<input type="submit" value="添加">
<input type="reset" value="重置"><br>
 
<div >
 
 
</body>
</html>

  liulan.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="Bean.Bean1" %>
<%@ page import="Dao.Dao1" %>
<%@ page import="Util.Util1" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>社团活动浏览</title>
</head>
<body>
<div align="center">
<form name="form" method="post" action="Screen.jsp">
<input type="submit" value="返回主页">
</form>
<table align="center" border="1" width="500">
<tr>
<th>活动主题</th>
<th>活动目的</th>
<th>活动类型</th>
<th>活动时间</th>
<th>活动地点</th>
<th>对象</th>
<th>活动内容</th>
<th>活动安排</th>
</tr>
<%
String sql = "SELECT * FROM `校园社团活动管理系统`";
Connection conn = Util1.getConn();
Statement state = null;
ResultSet rs = null;
Bean1 tbean=null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String zhuti = rs.getString("zhuti");
String mudi = rs.getString("mudi");
String leixing = rs.getString("leixing");
String shijian = rs.getString("shijian");
String didian = rs.getString("didian");
String duixiang = rs.getString("duixiang");
String neirong = rs.getString("neirong");
String anpai = rs.getString("anpai");
out.println("<tr>"+"<td>"+zhuti+"</td>");
out.println("<td>"+mudi+"</td>");
out.println("<td>"+leixing+"</td>");
out.println("<td>"+shijian+"</td>");
out.println("<td>"+didian+"</td>");
out.println("<td>"+duixiang+"</td>");
out.println("<td>"+neirong+"</td>");
out.println("<td>"+anpai+"</td>"+"</tr>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
Util1.close(rs, state, conn);
}
%>
 
 
 
</body>
</html>

  shanchu.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除界面</title>
</head>
<body>
<div align="center">
<form name="form" method="post" action="Screen.jsp">
<input type="submit" value="返回主页">
</form>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
 
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<form action="Servlet?method=delete" method="post" onsubmit="return check()">
请重新输入删除的主题
<input type="text" name="zhuti" />
  <input type="submit" value="删除" />
</body>
</html>             

  

xiugai.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<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>
<a href="Screen.jsp">返回主页</a>
<form name="form1" action="Servlet?method=update" method="post" onsubmit="return check()">
 
活动主题
<input type="text" name="zhuti"required pattern="^[\u4e00-\u9fa5]{1,20}"/>
<br>
活动目的
<input type="text" name="mudi"required pattern="^[\u4e00-\u9fa5]{1,50}"/><br>
活动类型
 
 <td>
            <input type="radio" name="leixing" value="社团竞赛" >社团竞赛
            <input type="radio" name="leixing" value="野外采风" >野外采风<br>
            <input type="radio" name="leixing" value="校内集会" >校内集会
            <input type="radio" name="leixing" value="社团纳新" >社团纳新
            </td><br>
活动时间
<input type="text" name="shijian"><br>
活动地点
<input type="text" name="didian"><br>
活动对象
 
 <tr>
                 
                <td>
 <input type="checkbox" name="duixiang" value="社团成员">社团成员
 <input type="checkbox" name="duixiang" value="全体学生">全体学生
 </td>
            </tr>
            <br>
活动内容
<input type="text" name="neirong"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
活动日程安排
<input type="text" name="anpai"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
<input type="submit" value="修改">
<input type="reset" value="重置"><br>
 
<div >
 
 
</body>
</html>

  

posted @   就叫清风吧  阅读(93)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示