01个人课堂练习
//policy
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
|
package bean; public class policy { private int id; private String name,type,category,range,document,form,organ,viadata,pubdata,perdata,text; public int getId() { return id; } public String getText() { return text; } public void setText(String text) { this .text = text; } public void setId( int id) { this .id = id; } public policy() { } public String getName() { return name; } public void setName(String name) { this .name = name; } public String getType() { return type; } public void setType(String type) { this .type = type; } public String getCategory() { return category; } public void setCategory(String category) { this .category = category; } public String getRange() { return range; } public void setRange(String range) { this .range = range; } public String getDocument() { return document; } public void setDocument(String document) { this .document = document; } public String getForm() { return form; } public void setForm(String form) { this .form = form; } public String getOrgan() { return organ; } public void setOrgan(String organ) { this .organ = organ; } public String getViadata() { return viadata; } public void setViadata(String viadata) { this .viadata = viadata; } public String getPubdata() { return pubdata; } public void setPubdata(String pubdata) { this .pubdata = pubdata; } public String getPerdata() { return perdata; } public void setPerdata(String perdata) { this .perdata = perdata; } @Override public String toString() { return "policy{" + "id=" + id + ", name='" + name + '\ '' + ", type='" + type + '\ '' + ", category='" + category + '\ '' + ", range='" + range + '\ '' + ", document='" + document + '\ '' + ", form='" + form + '\ '' + ", organ='" + organ + '\ '' + ", viadata='" + viadata + '\ '' + ", pubdata='" + pubdata + '\ '' + ", perdata='" + perdata + '\ '' + '}' ; } } |
//Dao
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
package dao; import bean.policy; import com.mysql.cj.jdbc.result.UpdatableResultSet; import util.DButil; import java.sql.*; import java.util.ArrayList; import java.util.List; import java.util.Set; public class Dao { public ArrayList<policy> getall(){ ArrayList<policy> policies= new ArrayList<>(); try { Connection connection= DButil.getConn(); String sql= "select * from policy" ; Statement statement=connection.createStatement(); ResultSet resultSet=statement.executeQuery(sql); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); policies.add(p); } } catch (Exception e){ e.printStackTrace(); } return policies; } public ArrayList<policy> chaxuntext( int cpage, int count){ String sql= "select * from policy order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); Statement statement = connection.createStatement(); ResultSet resultSet=statement.executeQuery(sql); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxunname( int cpage, int count,String name){ String sql= "select * from policy where name like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxundocument( int cpage, int count,String name){ String sql= "select * from policy where document like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxunorgan( int cpage, int count,String name){ String sql= "select * from policy where organ like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxun3( int cpage, int count,String name,String document,String organ){ String sql= "select * from policy where organ like ? and name like ? and document like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +organ+ "%" ); preparedStatement.setString( 2 , "%" +name+ "%" ); preparedStatement.setString( 3 , "%" +document+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxunnameanddocument( int cpage, int count,String name,String document){ String sql= "select * from policy where name like ? and document like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +name+ "%" ); preparedStatement.setString( 2 , "%" +document+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { e.printStackTrace(); } return texts; } public ArrayList<policy> chaxunnameandorgan( int cpage, int count,String name,String organ){ String sql= "select * from policy where name like ? and organ like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +name+ "%" ); preparedStatement.setString( 2 , "%" +organ+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public ArrayList<policy> chaxundocumentandorgan( int cpage, int count,String organ,String document){ String sql= "select * from policy where organ like ? and document like ? order by pubdata limit " +((cpage- 1 )*count)+ "," +count; ArrayList<policy> texts= new ArrayList<>(); try { Connection connection = DButil.getConn(); PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setString( 1 , "%" +organ+ "%" ); preparedStatement.setString( 2 , "%" +document+ "%" ); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ policy p= new policy(); p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); texts.add(p); } } catch (SQLException | ClassNotFoundException e) { throw new RuntimeException(e); } return texts; } public int [] alltext( int count){ String sql= "select count(*) from policy" ; int [] s= new int [ 2 ]; try { Connection connection=DButil.getConn(); Statement statement=connection.createStatement(); ResultSet resultSet=statement.executeQuery(sql); while (resultSet.next()){ s[ 0 ]=resultSet.getInt( 1 ); } if (s[ 0 ]%count== 0 ) s[ 1 ]=s[ 0 ]/count; else s[ 1 ]=s[ 0 ]/count+ 1 ; } catch (Exception e) { e.printStackTrace(); } return s; } public int [] allchaxunname( int count,String name){ String sql= "select count(*) from policy where name like ?" ; int [] s= new int [ 2 ]; try { Connection connection=DButil.getConn(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet= statement.executeQuery(); while (resultSet.next()){ s[ 0 ]=resultSet.getInt( 1 ); } if (s[ 0 ]%count== 0 ) s[ 1 ]=s[ 0 ]/count; else s[ 1 ]=s[ 0 ]/count+ 1 ; } catch (Exception e) { e.printStackTrace(); } return s; } public int [] allchaxundo( int count,String name){ String sql= "select count(*) from policy where document like ?" ; int [] s= new int [ 2 ]; try { Connection connection=DButil.getConn(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet= statement.executeQuery(); while (resultSet.next()){ s[ 0 ]=resultSet.getInt( 1 ); } if (s[ 0 ]%count== 0 ) s[ 1 ]=s[ 0 ]/count; else s[ 1 ]=s[ 0 ]/count+ 1 ; } catch (Exception e) { e.printStackTrace(); } return s; } public int [] allchaxunorgan( int count,String name){ String sql= "select count(*) from policy where organ like ?" ; int [] s= new int [ 2 ]; try { Connection connection=DButil.getConn(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString( 1 , "%" +name+ "%" ); ResultSet resultSet= statement.executeQuery(); while (resultSet.next()){ s[ 0 ]=resultSet.getInt( 1 ); } if (s[ 0 ]%count== 0 ) s[ 1 ]=s[ 0 ]/count; else s[ 1 ]=s[ 0 ]/count+ 1 ; } catch (Exception e) { e.printStackTrace(); } return s; } public policy getdetail( int id){ policy p= new policy(); try { Connection connection= DButil.getConn(); String sql= "select * from policy where id=?" ; PreparedStatement preparedStatement=connection.prepareStatement(sql); preparedStatement.setInt( 1 ,id); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ p.setId(resultSet.getInt( "id" )); p.setName(resultSet.getString( "name" )); p.setType(resultSet.getString( "type" )); p.setCategory(resultSet.getString( "category" )); p.setRange(resultSet.getString( "range" )); p.setDocument(resultSet.getString( "document" )); p.setForm(resultSet.getString( "form" )); p.setOrgan(resultSet.getString( "organ" )); p.setViadata(resultSet.getString( "viadata" )); p.setPubdata(resultSet.getString( "pubdata" )); p.setPerdata(resultSet.getString( "perdata" )); p.setText(resultSet.getString( "text" )); } } catch (Exception e){ e.printStackTrace(); } return p; } } |
//Servlet
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
|
package service; import bean.policy; import dao.Dao; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Servlet extends HttpServlet { Dao dao= new Dao(); public void service(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding( "UTF-8" ); String message=request.getParameter( "method" ); if (message.equals( "all" )){ all(request,response); } else if (message.equals( "chakan" )){ chakan(request,response); } else if (message.equals( "suoyou" )){ suoyou(request,response); } else if (message.equals( "chadata" )){ chadata(request,response); } } public void suoyou(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{ request.setCharacterEncoding( "UTF-8" ); response.setCharacterEncoding( "UTF-8" ); int cpage= 1 ; //当前页数 int count= 10 ; //每页显示数 String cp=request.getParameter( "cp" ); if (cp!= null ){ cpage=Integer.parseInt(cp); } int arr[]=dao.alltext(count); ArrayList<policy> policies= new ArrayList<>(); policies=dao.chaxuntext(cpage,count); request.setAttribute( "policies" ,policies); request.setAttribute( "cpage" ,cpage); request.setAttribute( "sum" ,arr[ 0 ]); request.setAttribute( "tpage" ,arr[ 1 ]); request.setAttribute( "dd" , "d" ); request.getRequestDispatcher( "index.jsp" ).forward(request,response); } public void chadata(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{ request.setCharacterEncoding( "UTF-8" ); response.setCharacterEncoding( "UTF-8" ); int cpage= 1 ; //当前页数 int count= 10 ; //每页显示数 String cp=request.getParameter( "cp" ); if (cp!= null ){ cpage=Integer.parseInt(cp); } int []s = new int [ 2 ]; int zero= 0 ; ArrayList<policy> policies= new ArrayList<>(); String name=request.getParameter( "name" ); String document=request.getParameter( "document" ); String organ=request.getParameter( "organ" ); if (name!= null &&!name.equals( "" )&&document!= null &&!document.equals( "" )&&organ!= null &&!organ.equals( "" )){ policies=dao.chaxun3(cpage,count,name,document,organ); } else if (name!= null &&!name.equals( "" )&&document!= null &&!document.equals( "" )){ policies=dao.chaxunnameanddocument(cpage,count,name,document); } else if (name!= null &&!name.equals( "" )&&organ!= null &&!organ.equals( "" )){ policies=dao.chaxunnameandorgan(cpage,count,name,organ); } else if (document!= null &&!document.equals( "" )&&organ!= null &&!organ.equals( "" )){ policies=dao.chaxundocumentandorgan(cpage,count,organ,document); } else if (name!= null &&!name.equals( "" )){ policies=dao.chaxunname(cpage,count,name); s=dao.allchaxunname(count,name); } else if (document!= null &&!document.equals( "" )){ policies=dao.chaxundocument(cpage,count,document); s=dao.allchaxundo(count,document); } else if (organ!= null &&!organ.equals( "" )){ policies=dao.chaxunorgan(cpage,count,organ); s=dao.allchaxunorgan(count,organ); } else { request.setAttribute( "message" , "未查询到相关信息" ); request.setAttribute( "policies" , null ); request.setAttribute( "cpage" ,zero); request.setAttribute( "sum" ,zero); request.setAttribute( "tpage" ,zero); request.getRequestDispatcher( "index.jsp" ).forward(request,response); return ; } if (policies.size()> 0 ) request.setAttribute( "policies" ,policies); else { request.setAttribute( "message" , "未查询到相关信息" ); request.setAttribute( "policies" , null ); request.setAttribute( "cpage" , 0 ); request.setAttribute( "sum" ,policies.size()); request.setAttribute( "tpage" ,policies.size()% 10 == 0 ?policies.size()/ 10 :policies.size()/ 10 + 1 ); request.getRequestDispatcher( "index.jsp" ).forward(request,response); return ; } request.setAttribute( "cpage" ,cpage); request.setAttribute( "sum" ,s[ 0 ]); request.setAttribute( "name" ,name); request.setAttribute( "organ" ,organ); request.setAttribute( "document" ,document); request.setAttribute( "tpage" ,s[ 1 ]); request.setAttribute( "dd" , "dd" ); request.getRequestDispatcher( "index.jsp" ).forward(request,response); } public void all(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding( "UTF-8" ); response.setCharacterEncoding( "UTF-8" ); ArrayList<policy> policies=dao.getall(); request.setAttribute( "policies" ,policies); request.getRequestDispatcher( "index.jsp" ).forward(request,response); } public void chakan(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding( "UTF-8" ); response.setCharacterEncoding( "UTF-8" ); String id0=request.getParameter( "id" ); int id=Integer.parseInt(id0); policy p=dao.getdetail(id); request.setAttribute( "policy" ,p); request.getRequestDispatcher( "detail.jsp" ).forward(request,response); } } |
//DButil
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
|
package util; import java.sql.*; public class DButil { public static Connection getConn() throws ClassNotFoundException { Connection connection= null ; try { Class.forName( "com.mysql.cj.jdbc.Driver" ); connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/st" , "root" , "byc666" ); } catch (Exception e){ e.printStackTrace(); } return connection; } public static void closeall(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){ try { if (resultSet!= null ) resultSet.close(); } catch (SQLException e) { throw new RuntimeException(e); } try { if (preparedStatement!= null ) preparedStatement.close(); } catch (SQLException e) { throw new RuntimeException(e); } try { if (connection!= null ) connection.close(); } catch (SQLException e) { throw new RuntimeException(e); } } } |
//detail.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
|
<%-- Created by IntelliJ IDEA. User: Lenovo Date: 2023 / 4 / 10 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</title> <link href= "table.css" rel= "stylesheet" > </head> <body> <center> <table class = "tb" border= "0" > <th>正文</th> <tr> <td>${policy.text}</td> </tr> </table> </center> </body> </html> |
//index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<%@ taglib prefix= "c" uri= "http://java.sun.com/jsp/jstl/core" %> <%@ page import = "java.util.ArrayList" %> <%@ page import = "bean.policy" %><%-- Created by IntelliJ IDEA. User: Lenovo Date: 2023 / 4 / 10 Time: 15 : 19 To change this template use File | Settings | File Templates. --%> <%@ page contentType= "text/html;charset=UTF-8" language= "java" %> <html> <head> <link href= "table.css" rel= "stylesheet" > <title>Title</title> </head> <body> <center> <img src= "LOGO.png" > </center> <% request.setCharacterEncoding( "UTF-8" ); response.setCharacterEncoding( "UTF-8" ); Object message=request.getAttribute( "message" ); if (message!= null ) { %> <script language= "JavaScript" >alert( "<%=message%>" )</script> <% } ArrayList<policy> policies= (ArrayList<policy>) request.getAttribute( "policies" ); if (policies== null ){ %> <form action= "Servlet?method=suoyou" method= "post" > <input type= "submit" value= "查询" > </form> <% } else if (policies!= null ){ %> <center> <form action= "Servlet?method=chadata" method= "post" > 政策名称:<input type= "text" name= "name" placeholder= "请输入政策名称" style= "border: none" > 发文字号:<input type= "text" name= "document" placeholder= "请输入发文字号" style= "border: none" > 发文机构:<input type= "text" name= "organ" placeholder= "请输入发文机构" style= "border: none" > 全文检索:<input type= "text" name= "data" style= "border: none" > <input type= "submit" value= "搜索" > </form> <br> <br> <table border= "0" cellspacing= "0" > <th width= "10%" >id</th><th width= "20%" >政策名称</th><th width= "20%" >发文机构</th><th width= "20%" >颁布日期</th><th width= "20%" >政策分类</th><th width= "10%" >操作</th> <c:forEach items= "${policies}" var= "item" > <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.organ}</td> <td>${item.pubdata}</td> <td>${item.type}</td> <td><a href= "Servlet?method=chakan&id=${item.id}" style= "text-decoration: none" >查看</a> </td> </tr> </c:forEach> </table> <br> 共${sum}条记录,当前第${cpage}/${tpage}页 <% String dd= request.getAttribute( "dd" ).toString(); if (Integer.parseInt(request.getAttribute( "sum" ).toString())< 10 ){ } else if (dd.equals( "d" )){%> <a href= "Servlet?method=suoyou&cp=1" >首页</a> <a href= "Servlet?method=suoyou&cp=${cpage-1<=0?1:cpage-1}" >上一页</a> <a href= "Servlet?method=suoyou&cp=${cpage+1>=tpage?tpage:cpage+1}" >下一页</a> <a href= "Servlet?method=suoyou&cp=${tpage}" >尾页</a> <% } else if (dd.equals( "dd" )){%> <a href= "Servlet?method=chadata&cp=1&name=<%=request.getAttribute(" name ")%>&document=<%=request.getAttribute(" document ")%>&organ=<%=request.getAttribute(" organ ")%>" >首页</a> <a href= "Servlet?method=chadata&cp=${cpage-1<=0?1:cpage-1}&name=<%=request.getAttribute(" name ")%>&document=<%=request.getAttribute(" document ")%>&organ=<%=request.getAttribute(" organ ")%>" >上一页</a> <a href= "Servlet?method=chadata&cp=${cpage+1>=tpage?tpage:cpage+1}&name=<%=request.getAttribute(" name ")%>&document=<%=request.getAttribute(" document ")%>&organ=<%=request.getAttribute(" organ ")%>" >下一页</a> <a href= "Servlet?method=chadata&cp=${tpage}&name=<%=request.getAttribute(" name ")%>&document=<%=request.getAttribute(" document ")%>&organ=<%=request.getAttribute(" organ ")%>" >尾页</a> <% } %> </center> <% } %> </body> </html> |
//table.css
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
|
* { padding: 0 ; margin: 0 ; font-family: 'Open Sans Light' ; letter-spacing: .05em; margin: 0 auto; text-align: center; } html { height: 100 %; } body { height: 100 %; font: normal 20px auto “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; background: #E6EAE9; } a { color: #c75f3e; } table { width: 100 %; padding: 0 ; margin: 0 ; } caption { padding: 0 0 5px 0 ; width: max-content; font: italic 30px “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif; text-align: right; } th { font: bold 30px “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; border: 0 ; letter-spacing: 2px; text-transform: uppercase; text-align: center; height: 40px; padding: 6px 6px 6px 12px; background: #CAE8EA no-repeat; background-size: cover; } th.nobg { border-top: 0 ; border-left: 0 ; border: 0 ; background: none; } td { height: 30px; border: 0 ; background: #fff; font-size:30px; color: #4f6b72; } th.spec { border-left: 1px solid #C1DAD7; border-top: 0 ; background: #fff no-repeat; font: bold 10px “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif; } th.specalt { border-left: 1px solid #C1DAD7; border-top: 0 ; background: #f5fafa no-repeat; font: bold 10px “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif; color: # 797268 ; } td.alt { background: #F5FAFA; color: # 797268 ; } /*———for IE 5.x bug*/ html>body td{ font-size:20px;} body,td,th { font-family: 宋体, Arial; font-size: 15px; } |