質問編集履歴
8
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
サーブレットからJSPの受け渡しがうまくいかないです。
|
test
CHANGED
@@ -2,21 +2,13 @@
|
|
2
2
|
|
3
3
|
プログラミング、java共に初心者です。
|
4
4
|
|
5
|
-
授業で部署の管理システムというものを作っており、
|
6
|
-
|
7
|
-
画面でコードと部署名を入力し、
|
8
|
-
|
9
|
-
登録ボタンを押すとコードと部署名の追加と変更を行う、
|
10
|
-
|
11
|
-
|
5
|
+
授業でサーブレットからJSPに画面遷移するプログラムを作ろうとしています。
|
12
|
-
|
13
|
-
|
14
6
|
|
15
7
|
###発生している問題・エラーメッセージ
|
16
8
|
|
17
9
|
Initを実行すると、初期表示はされるのですが、何も入力せずに登録ボタンを押す、
|
18
10
|
|
19
|
-
また
|
11
|
+
またコード、部署名を入力し追加ボタンを押してもHTTPステータス404(The requested resource is not available.) が表示されエラーになってしまう状態です。
|
20
12
|
|
21
13
|
|
22
14
|
|
@@ -40,7 +32,7 @@
|
|
40
32
|
|
41
33
|
```lang-言語名
|
42
34
|
|
43
|
-
package
|
35
|
+
package kanri;
|
44
36
|
|
45
37
|
|
46
38
|
|
@@ -110,7 +102,7 @@
|
|
110
102
|
|
111
103
|
|
112
104
|
|
113
|
-
|
105
|
+
|
114
106
|
|
115
107
|
|
116
108
|
|
@@ -140,7 +132,7 @@
|
|
140
132
|
|
141
133
|
//
|
142
134
|
|
143
|
-
D
|
135
|
+
D bean = new Dept();
|
144
136
|
|
145
137
|
bean.setDno(d_no);
|
146
138
|
|
@@ -158,38 +150,20 @@
|
|
158
150
|
|
159
151
|
request.setAttribute("depts", d_list);
|
160
152
|
|
161
|
-
RequestDispatcher rd = request.getRequestDispatcher("0
|
153
|
+
RequestDispatcher rd = request.getRequestDispatcher("001.jsp");
|
162
154
|
|
163
155
|
rd.forward(request, response);
|
164
156
|
|
165
157
|
|
166
158
|
|
167
|
-
|
159
|
+
|
168
|
-
|
169
|
-
|
160
|
+
|
161
|
+
|
170
162
|
|
171
163
|
}
|
172
164
|
|
173
165
|
|
174
166
|
|
175
|
-
finally {
|
176
|
-
|
177
|
-
try {
|
178
|
-
|
179
|
-
conn.close();
|
180
|
-
|
181
|
-
} catch (Exception ex) {
|
182
|
-
|
183
|
-
;
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
167
|
}
|
194
168
|
|
195
169
|
|
@@ -208,548 +182,206 @@
|
|
208
182
|
|
209
183
|
```
|
210
184
|
|
185
|
+
|
186
|
+
|
211
|
-
###該当のソースコード(
|
187
|
+
###該当のソースコード(Class Dept)
|
212
188
|
|
213
189
|
```lang-言語名
|
214
190
|
|
215
|
-
package
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
i
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
i
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
public
|
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
|
-
String tourokuFlag = request.getParameter("fg");
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
DeptBean bean = new Dept();
|
286
|
-
|
287
|
-
bean.setDeptno(p_no);
|
288
|
-
|
289
|
-
bean.setDname(p_name);
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
boolean is_error = false;
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if (Fg != null) {
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
if (bean.getDno() == null ||
|
302
|
-
|
303
|
-
bean.getDname() == null ||
|
304
|
-
|
305
|
-
bean.getDno().trim().equals("")||
|
306
|
-
|
307
|
-
bean.getDname().trim().equals("")
|
308
|
-
|
309
|
-
) {
|
310
|
-
|
311
|
-
is_error = true;
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
request.setAttribute("dept", bean);
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
String jsp = "03.jsp";
|
322
|
-
|
323
|
-
if (is_error) {
|
324
|
-
|
325
|
-
jsp = "03.jsp";
|
326
|
-
|
327
|
-
request.setAttribute("err_msg", "データが全て入力されていません");
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
RequestDispatcher rd = request.getRequestDispatcher(jsp_page);
|
332
|
-
|
333
|
-
rd.forward(request, response);
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
conn = Uty.getConnection();
|
342
|
-
|
343
|
-
PreparedStatement ppst = conn.prepareStatement(sql);
|
344
|
-
|
345
|
-
ppst.setString(1,bean.getDno());
|
346
|
-
|
347
|
-
ppst.setString(2,bean.getDname());
|
348
|
-
|
349
|
-
int count = ppst.executeUpdate();
|
350
|
-
|
351
|
-
conn.close();
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
String msg = "完了しました";
|
356
|
-
|
357
|
-
if(count < 1){
|
358
|
-
|
359
|
-
msg = "エラー";
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
}
|
364
|
-
|
365
|
-
request.setAttribute("dept",bean);
|
366
|
-
|
367
|
-
request.setAttribute("err_msg",msg);
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
RequestDispatcher rd = request.getRequestDispatcher("03.jsp");
|
372
|
-
|
373
|
-
rd.forward(request,response);
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
catch (Exception ex) {
|
382
|
-
|
383
|
-
ex.printStackTrace();
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
finally {
|
388
|
-
|
389
|
-
try {
|
390
|
-
|
391
|
-
conn.close();
|
392
|
-
|
393
|
-
} catch (Exception ex) {
|
394
|
-
|
395
|
-
;
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
}
|
402
|
-
|
403
|
-
}
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
408
|
-
|
409
|
-
throws ServletException, IOException {
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
doGet(request, response);
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
}
|
191
|
+
package kanri;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
public class Dt{
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
private String m_no = "";
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
public String getDno() {
|
206
|
+
|
207
|
+
return this.m_no;
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
public void setDno(String dno) {
|
216
|
+
|
217
|
+
this.m_no = dno;
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
private String m_name = "";
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
public String getDname() {
|
230
|
+
|
231
|
+
return this.m_name;
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
public void setDname(String dname) {
|
240
|
+
|
241
|
+
this.m_name = dname;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
420
256
|
|
421
257
|
```
|
422
258
|
|
259
|
+
|
260
|
+
|
423
|
-
###該当のソースコード(
|
261
|
+
###該当のソースコード(JSP)
|
424
262
|
|
425
263
|
```lang-言語名
|
426
264
|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
p
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
pu
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
p
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
t
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
265
|
+
|
266
|
+
|
267
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
268
|
+
|
269
|
+
pageEncoding="UTF-8"%>
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
<%@page import="java.util.ArrayList"%>
|
274
|
+
|
275
|
+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
276
|
+
|
277
|
+
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
284
|
+
|
285
|
+
<html>
|
286
|
+
|
287
|
+
<head>
|
288
|
+
|
289
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
290
|
+
|
291
|
+
<title>部署管理</title>
|
292
|
+
|
293
|
+
</head>
|
294
|
+
|
295
|
+
<body>
|
296
|
+
|
297
|
+
<form method="post" action="insert">
|
298
|
+
|
299
|
+
<input type="hidden" name="fg" value="true">
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<h1>部署管理</h1>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
</div>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
<center>
|
312
|
+
|
313
|
+
<table>
|
314
|
+
|
315
|
+
<tr>
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<td>コード</td>
|
320
|
+
|
321
|
+
<td><input type="text" name="no" ></td>
|
322
|
+
|
323
|
+
<td width = 30>
|
324
|
+
|
325
|
+
<td><button type="submit" name="fg"> 登 録</button></td>
|
326
|
+
|
327
|
+
</tr>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
</tr>
|
334
|
+
|
335
|
+
</table>
|
336
|
+
|
337
|
+
</center>
|
338
|
+
|
339
|
+
</form>
|
340
|
+
|
341
|
+
<form method="post" action="Init">
|
342
|
+
|
343
|
+
<center>
|
344
|
+
|
345
|
+
<table border=1 height="300" width="350">
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
<tr bgcolor="#4169e1">
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
<th></th>
|
354
|
+
|
355
|
+
<th width="2">コード</th>
|
356
|
+
|
357
|
+
<th width="30">部署</th>
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
</table>
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
</center>
|
370
|
+
|
371
|
+
</form>
|
372
|
+
|
373
|
+
</body>
|
374
|
+
|
375
|
+
</html>
|
490
376
|
|
491
377
|
|
492
378
|
|
493
379
|
```
|
494
380
|
|
495
|
-
###該当のソースコード(class Uty)
|
496
|
-
|
497
|
-
```lang-言語名
|
498
|
-
|
499
|
-
package kanri;
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
import java.sql.Connection;
|
504
|
-
|
505
|
-
import java.sql.ResultSet;
|
506
|
-
|
507
|
-
import java.sql.SQLException;
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
import javax.naming.Context;
|
512
|
-
|
513
|
-
import javax.naming.NamingException;
|
514
|
-
|
515
|
-
import javax.sql.DataSource;
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
public class Uty {
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
public static Connection getConnection() throws NamingException, SQLException{
|
526
|
-
|
527
|
-
String judi_url = "java:comp/env/jdbc/sample";
|
528
|
-
|
529
|
-
Context ctx = new javax.naming.InitialContext();
|
530
|
-
|
531
|
-
DataSource ds = (javax.sql.DataSource)ctx.lookup(judi_url);
|
532
|
-
|
533
|
-
Connection conn =ds.getConnection();
|
534
|
-
|
535
|
-
return conn;
|
536
|
-
|
537
|
-
}
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
public static void setDeptBeanFromRs(Deptbean,ResultSet rs) throws SQLException{
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
bean.setDeptno(rs.getString("NO"));
|
550
|
-
|
551
|
-
bean.setDeptname(rs.getString("NAME"));
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
}
|
556
|
-
|
557
|
-
}
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
```
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
###該当のソースコード(JSP)
|
566
|
-
|
567
|
-
```lang-言語名
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
572
|
-
|
573
|
-
pageEncoding="UTF-8"%>
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
<%@page import="java.util.ArrayList"%>
|
578
|
-
|
579
|
-
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
580
|
-
|
581
|
-
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
588
|
-
|
589
|
-
<html>
|
590
|
-
|
591
|
-
<head>
|
592
|
-
|
593
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
594
|
-
|
595
|
-
<title>部署管理</title>
|
596
|
-
|
597
|
-
</head>
|
598
|
-
|
599
|
-
<body>
|
600
|
-
|
601
|
-
<form method="post" action="insert">
|
602
|
-
|
603
|
-
<input type="hidden" name="fg" value="true">
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
<h1>部署管理</h1>
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
</div>
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
<center>
|
616
|
-
|
617
|
-
<table>
|
618
|
-
|
619
|
-
<tr>
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
<td>部署コード</td>
|
624
|
-
|
625
|
-
<td><input type="text" name="deptno" id = "textforscb3" ></td>
|
626
|
-
|
627
|
-
<td width = 30>
|
628
|
-
|
629
|
-
<td><button type="submit" name="fg"> 登 録</button></td>
|
630
|
-
|
631
|
-
</tr>
|
632
|
-
|
633
|
-
<tr>
|
634
|
-
|
635
|
-
<td>部署名</td>
|
636
|
-
|
637
|
-
<td> <input type="text" name="dname"></td>
|
638
|
-
|
639
|
-
<td width = 30>
|
640
|
-
|
641
|
-
<td><button type="submit" >変 更</button></td>
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
</tr>
|
648
|
-
|
649
|
-
</table>
|
650
|
-
|
651
|
-
</center>
|
652
|
-
|
653
|
-
</form>
|
654
|
-
|
655
|
-
<br>
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
<form method="post" action="Init">
|
662
|
-
|
663
|
-
<center>
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
<table border=1 height="300" width="350" bgcolor="#f5f5f5">
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
<tr bgcolor="#4169e1">
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
<th></th>
|
676
|
-
|
677
|
-
<th width="2">コード</th>
|
678
|
-
|
679
|
-
<th width="30">部署</th>
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
<c:forEach var="dept" items="${depts}">
|
686
|
-
|
687
|
-
<tr>
|
688
|
-
|
689
|
-
<td style = "width:3px">
|
690
|
-
|
691
|
-
<input type="checkbox" class="ck" onclick="connecttext('textforscb3',this.checked);" /></td>
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
<td>${dept.dno}</td>
|
702
|
-
|
703
|
-
<td>${dept.dname}</td>
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
</tr>
|
708
|
-
|
709
|
-
</c:forEach>
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
</table>
|
714
|
-
|
715
|
-
</div>
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
</center>
|
720
|
-
|
721
|
-
</form>
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
<br>
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
</body>
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
</html>
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
```
|
746
|
-
|
747
381
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
748
382
|
|
749
383
|
initが初期表示のサーブレット
|
750
384
|
|
751
|
-
insertが空白判定と追加の処理
|
752
|
-
|
753
385
|
jspが画面表示用です。
|
754
386
|
|
755
387
|
|
7
文法修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
javaで
|
1
|
+
javaで部署管理
|
test
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
プログラミング、java共に初心者です。
|
4
4
|
|
5
|
-
|
5
|
+
授業で部署の管理システムというものを作っており、
|
6
|
-
|
6
|
+
|
7
|
-
|
7
|
+
画面でコードと部署名を入力し、
|
8
|
-
|
8
|
+
|
9
|
-
登録ボタンを押すと
|
9
|
+
登録ボタンを押すとコードと部署名の追加と変更を行う、
|
10
|
-
|
10
|
+
|
11
|
-
空白のまま登録ボタンを押すと
|
11
|
+
空白のまま登録ボタンを押すと登録できないシステムを作ろうとしています。
|
12
12
|
|
13
13
|
|
14
14
|
|
15
15
|
###発生している問題・エラーメッセージ
|
16
16
|
|
17
|
-
|
17
|
+
Initを実行すると、初期表示はされるのですが、何も入力せずに登録ボタンを押す、
|
18
18
|
|
19
19
|
また部署コード、部署名を入力し追加ボタンを押してもHTTPステータス404(The requested resource is not available.) が表示されエラーになってしまう状態です。
|
20
20
|
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
###該当のソースコード(
|
39
|
+
###該当のソースコード(init)
|
40
40
|
|
41
41
|
```lang-言語名
|
42
42
|
|
@@ -70,13 +70,13 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
public class
|
73
|
+
public class init extends HttpServlet {
|
74
74
|
|
75
75
|
private static final long serialVersionUID = 1L;
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
-
public
|
79
|
+
public init() {
|
80
80
|
|
81
81
|
super();
|
82
82
|
|
@@ -90,17 +90,17 @@
|
|
90
90
|
|
91
91
|
throws ServletException, IOException {
|
92
92
|
|
93
|
-
String driver =
|
93
|
+
//String driver =
|
94
|
-
|
94
|
+
|
95
|
-
String url =
|
95
|
+
//String url =
|
96
|
-
|
96
|
+
|
97
|
-
String user = "postgres";
|
97
|
+
//String user = "postgres";
|
98
98
|
|
99
99
|
//String pwd =
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
-
String sql
|
103
|
+
String sql = "Select * from DEPT order by d_no";
|
104
104
|
|
105
105
|
Connection conn = null;
|
106
106
|
|
@@ -124,31 +124,31 @@
|
|
124
124
|
|
125
125
|
Statement stmt = conn.createStatement();
|
126
126
|
|
127
|
-
ResultSet rs = stmt.executeQuery(sql
|
127
|
+
ResultSet rs = stmt.executeQuery(sql);
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
-
ArrayList<Dept
|
131
|
+
ArrayList<Dept> dept_list = new ArrayList<Dept>();
|
132
132
|
|
133
133
|
while (rs.next()) {
|
134
134
|
|
135
|
-
String dept_no = rs.getString("D
|
135
|
+
String dept_no = rs.getString("D_NO");
|
136
|
-
|
136
|
+
|
137
|
-
String dept_name = rs.getString("D
|
137
|
+
String dept_name = rs.getString("D_NAME");
|
138
138
|
|
139
139
|
|
140
140
|
|
141
141
|
//
|
142
142
|
|
143
|
-
Dept
|
143
|
+
Dept bean = new Dept();
|
144
|
-
|
144
|
+
|
145
|
-
bean.setD
|
145
|
+
bean.setDno(d_no);
|
146
|
-
|
146
|
+
|
147
|
-
bean.setD
|
147
|
+
bean.setDname(d_name);
|
148
148
|
|
149
149
|
//
|
150
150
|
|
151
|
-
d
|
151
|
+
d_list.add(bean);
|
152
152
|
|
153
153
|
}
|
154
154
|
|
@@ -156,9 +156,9 @@
|
|
156
156
|
|
157
157
|
|
158
158
|
|
159
|
-
request.setAttribute("depts", d
|
159
|
+
request.setAttribute("depts", d_list);
|
160
|
-
|
160
|
+
|
161
|
-
RequestDispatcher rd = request.getRequestDispatcher("
|
161
|
+
RequestDispatcher rd = request.getRequestDispatcher("03.jsp");
|
162
162
|
|
163
163
|
rd.forward(request, response);
|
164
164
|
|
@@ -208,7 +208,7 @@
|
|
208
208
|
|
209
209
|
```
|
210
210
|
|
211
|
-
###該当のソースコード(
|
211
|
+
###該当のソースコード(Insert)
|
212
212
|
|
213
213
|
```lang-言語名
|
214
214
|
|
@@ -236,13 +236,13 @@
|
|
236
236
|
|
237
237
|
|
238
238
|
|
239
|
-
public class
|
239
|
+
public class Insert extends HttpServlet {
|
240
240
|
|
241
241
|
private static final long serialVersionUID = 1L;
|
242
242
|
|
243
243
|
|
244
244
|
|
245
|
-
public
|
245
|
+
public Insert() {
|
246
246
|
|
247
247
|
super();
|
248
248
|
|
@@ -260,7 +260,7 @@
|
|
260
260
|
|
261
261
|
Connection conn = null;
|
262
262
|
|
263
|
-
String sql = "insert into (D
|
263
|
+
String sql = "insert into (D_NO,D_NAME)values(?, ?)";
|
264
264
|
|
265
265
|
|
266
266
|
|
@@ -274,19 +274,19 @@
|
|
274
274
|
|
275
275
|
|
276
276
|
|
277
|
-
String pm_
|
277
|
+
String pm_no = request.getParameter("fg");
|
278
|
-
|
278
|
+
|
279
|
-
String pm_
|
279
|
+
String pm_name = request.getParameter("dname");
|
280
|
-
|
280
|
+
|
281
|
-
String tourokuFlag = request.getParameter("
|
281
|
+
String tourokuFlag = request.getParameter("fg");
|
282
|
-
|
283
|
-
|
284
|
-
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
-
DeptBean bean = new Dept
|
285
|
+
DeptBean bean = new Dept();
|
286
|
-
|
286
|
+
|
287
|
-
bean.setDeptno(p
|
287
|
+
bean.setDeptno(p_no);
|
288
|
-
|
288
|
+
|
289
|
-
bean.setD
|
289
|
+
bean.setDname(p_name);
|
290
290
|
|
291
291
|
|
292
292
|
|
@@ -294,17 +294,17 @@
|
|
294
294
|
|
295
295
|
|
296
296
|
|
297
|
-
if (
|
297
|
+
if (Fg != null) {
|
298
|
-
|
299
|
-
|
300
|
-
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
-
if (bean.getD
|
301
|
+
if (bean.getDno() == null ||
|
302
|
-
|
302
|
+
|
303
|
-
bean.getD
|
303
|
+
bean.getDname() == null ||
|
304
|
-
|
304
|
+
|
305
|
-
bean.getD
|
305
|
+
bean.getDno().trim().equals("")||
|
306
|
-
|
306
|
+
|
307
|
-
bean.getD
|
307
|
+
bean.getDname().trim().equals("")
|
308
308
|
|
309
309
|
) {
|
310
310
|
|
@@ -318,11 +318,11 @@
|
|
318
318
|
|
319
319
|
|
320
320
|
|
321
|
-
String jsp
|
321
|
+
String jsp = "03.jsp";
|
322
322
|
|
323
323
|
if (is_error) {
|
324
324
|
|
325
|
-
jsp
|
325
|
+
jsp = "03.jsp";
|
326
326
|
|
327
327
|
request.setAttribute("err_msg", "データが全て入力されていません");
|
328
328
|
|
@@ -342,9 +342,9 @@
|
|
342
342
|
|
343
343
|
PreparedStatement ppst = conn.prepareStatement(sql);
|
344
344
|
|
345
|
-
ppst.setString(1,bean.getD
|
345
|
+
ppst.setString(1,bean.getDno());
|
346
|
-
|
346
|
+
|
347
|
-
ppst.setString(2,bean.getD
|
347
|
+
ppst.setString(2,bean.getDname());
|
348
348
|
|
349
349
|
int count = ppst.executeUpdate();
|
350
350
|
|
@@ -352,11 +352,11 @@
|
|
352
352
|
|
353
353
|
|
354
354
|
|
355
|
-
String msg = "
|
355
|
+
String msg = "完了しました";
|
356
356
|
|
357
357
|
if(count < 1){
|
358
358
|
|
359
|
-
msg = "
|
359
|
+
msg = "エラー";
|
360
360
|
|
361
361
|
|
362
362
|
|
@@ -368,7 +368,7 @@
|
|
368
368
|
|
369
369
|
|
370
370
|
|
371
|
-
RequestDispatcher rd = request.getRequestDispatcher("
|
371
|
+
RequestDispatcher rd = request.getRequestDispatcher("03.jsp");
|
372
372
|
|
373
373
|
rd.forward(request,response);
|
374
374
|
|
@@ -420,27 +420,27 @@
|
|
420
420
|
|
421
421
|
```
|
422
422
|
|
423
|
-
###該当のソースコード(Class Dept
|
423
|
+
###該当のソースコード(Class Dept)
|
424
424
|
|
425
425
|
```lang-言語名
|
426
426
|
|
427
|
-
package
|
427
|
+
package kanri;
|
428
|
-
|
429
|
-
|
430
|
-
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
-
public class Dept
|
431
|
+
public class Dept{
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
-
private String m_
|
437
|
+
private String m_no = "";
|
438
438
|
|
439
439
|
|
440
440
|
|
441
441
|
public String getDeptno() {
|
442
442
|
|
443
|
-
return this.m_
|
443
|
+
return this.m_no;
|
444
444
|
|
445
445
|
|
446
446
|
|
@@ -450,7 +450,7 @@
|
|
450
450
|
|
451
451
|
public void setDeptno(String deptno) {
|
452
452
|
|
453
|
-
this.m_
|
453
|
+
this.m_no = dno;
|
454
454
|
|
455
455
|
|
456
456
|
|
@@ -462,9 +462,9 @@
|
|
462
462
|
|
463
463
|
|
464
464
|
|
465
|
-
public String getD
|
465
|
+
public String getDname() {
|
466
|
-
|
466
|
+
|
467
|
-
return this.m_
|
467
|
+
return this.m_name;
|
468
468
|
|
469
469
|
|
470
470
|
|
@@ -472,9 +472,9 @@
|
|
472
472
|
|
473
473
|
|
474
474
|
|
475
|
-
public void setD
|
475
|
+
public void setDname(String dname) {
|
476
|
-
|
476
|
+
|
477
|
-
this.m_
|
477
|
+
this.m_name = dname;
|
478
478
|
|
479
479
|
|
480
480
|
|
@@ -496,7 +496,7 @@
|
|
496
496
|
|
497
497
|
```lang-言語名
|
498
498
|
|
499
|
-
package
|
499
|
+
package kanri;
|
500
500
|
|
501
501
|
|
502
502
|
|
@@ -538,38 +538,22 @@
|
|
538
538
|
|
539
539
|
|
540
540
|
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
541
|
-
public static void set
|
545
|
+
public static void setDeptBeanFromRs(Deptbean,ResultSet rs) throws SQLException{
|
542
|
-
|
543
|
-
|
546
|
+
|
544
|
-
|
547
|
+
|
548
|
+
|
545
|
-
bean.setDeptno(rs.getString("
|
549
|
+
bean.setDeptno(rs.getString("NO"));
|
546
|
-
|
550
|
+
|
547
|
-
bean.set
|
551
|
+
bean.setDeptname(rs.getString("NAME"));
|
548
|
-
|
549
|
-
|
552
|
+
|
550
|
-
|
551
|
-
|
553
|
+
|
552
|
-
|
553
|
-
bean.setGender(rs.getInt("GENDER"));
|
554
|
-
|
555
|
-
bean.setRemarks(rs.getString("REMARKS"));
|
556
554
|
|
557
555
|
}
|
558
556
|
|
559
|
-
|
560
|
-
|
561
|
-
public static void setDeptBeanFromRs(DeptBean bean,ResultSet rs) throws SQLException{
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
bean.setDeptno(rs.getString("DEPT_NO"));
|
566
|
-
|
567
|
-
bean.setDeptname(rs.getString("DEPT_NAME"));
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
}
|
572
|
-
|
573
557
|
}
|
574
558
|
|
575
559
|
|
@@ -592,8 +576,6 @@
|
|
592
576
|
|
593
577
|
<%@page import="java.util.ArrayList"%>
|
594
578
|
|
595
|
-
<%@page import="seminar.EmpBean"%>
|
596
|
-
|
597
579
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
598
580
|
|
599
581
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
@@ -610,27 +592,25 @@
|
|
610
592
|
|
611
593
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
612
594
|
|
613
|
-
<title>
|
595
|
+
<title>部署管理</title>
|
614
596
|
|
615
597
|
</head>
|
616
598
|
|
617
599
|
<body>
|
618
600
|
|
619
|
-
<form method="post" action="
|
601
|
+
<form method="post" action="insert">
|
620
|
-
|
602
|
+
|
621
|
-
<input type="hidden" name="
|
603
|
+
<input type="hidden" name="fg" value="true">
|
622
|
-
|
623
|
-
|
604
|
+
|
624
|
-
|
625
|
-
|
626
|
-
|
605
|
+
|
606
|
+
|
627
|
-
<h1>
|
607
|
+
<h1>部署管理</h1>
|
628
608
|
|
629
609
|
|
630
610
|
|
631
611
|
</div>
|
632
612
|
|
633
|
-
|
613
|
+
|
634
614
|
|
635
615
|
<center>
|
636
616
|
|
@@ -646,7 +626,7 @@
|
|
646
626
|
|
647
627
|
<td width = 30>
|
648
628
|
|
649
|
-
<td><button type="submit" name="
|
629
|
+
<td><button type="submit" name="fg"> 登 録</button></td>
|
650
630
|
|
651
631
|
</tr>
|
652
632
|
|
@@ -654,11 +634,11 @@
|
|
654
634
|
|
655
635
|
<td>部署名</td>
|
656
636
|
|
657
|
-
<td> <input type="text" name="d
|
637
|
+
<td> <input type="text" name="dname"></td>
|
658
638
|
|
659
639
|
<td width = 30>
|
660
640
|
|
661
|
-
<td><button type="submit"
|
641
|
+
<td><button type="submit" >変 更</button></td>
|
662
642
|
|
663
643
|
|
664
644
|
|
@@ -678,13 +658,13 @@
|
|
678
658
|
|
679
659
|
|
680
660
|
|
681
|
-
<form method="post" action="
|
661
|
+
<form method="post" action="Init">
|
682
662
|
|
683
663
|
<center>
|
684
664
|
|
685
|
-
|
665
|
+
|
686
|
-
|
666
|
+
|
687
|
-
<table border=
|
667
|
+
<table border=1 height="300" width="350" bgcolor="#f5f5f5">
|
688
668
|
|
689
669
|
|
690
670
|
|
@@ -694,9 +674,9 @@
|
|
694
674
|
|
695
675
|
<th></th>
|
696
676
|
|
697
|
-
<th width="2">
|
677
|
+
<th width="2">コード</th>
|
698
|
-
|
678
|
+
|
699
|
-
<th width="30">部署
|
679
|
+
<th width="30">部署</th>
|
700
680
|
|
701
681
|
|
702
682
|
|
@@ -718,9 +698,9 @@
|
|
718
698
|
|
719
699
|
|
720
700
|
|
721
|
-
<td>${dept.d
|
701
|
+
<td>${dept.dno}</td>
|
722
|
-
|
702
|
+
|
723
|
-
<td>${dept.d
|
703
|
+
<td>${dept.dname}</td>
|
724
704
|
|
725
705
|
|
726
706
|
|
@@ -750,14 +730,6 @@
|
|
750
730
|
|
751
731
|
|
752
732
|
|
753
|
-
<DIV align="right" style="margin-right:160px">
|
754
|
-
|
755
|
-
<button type="submit" style="background-color:steelblue;;width:170px;height:30px;margin-right:150px;"><font color="#fffaf">削 除</font></button>
|
756
|
-
|
757
|
-
</Div>
|
758
|
-
|
759
|
-
|
760
|
-
|
761
733
|
|
762
734
|
|
763
735
|
</body>
|
@@ -774,39 +746,19 @@
|
|
774
746
|
|
775
747
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
776
748
|
|
777
|
-
|
749
|
+
initが初期表示のサーブレット
|
778
|
-
|
750
|
+
|
779
|
-
|
751
|
+
insertが空白判定と追加の処理
|
780
|
-
|
752
|
+
|
781
|
-
jsp
|
753
|
+
jspが画面表示用です。
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
754
|
+
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
755
|
+
|
794
|
-
|
795
|
-
|
756
|
+
|
796
|
-
|
797
|
-
|
757
|
+
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
758
|
+
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
759
|
+
|
806
|
-
|
807
|
-
|
760
|
+
|
808
|
-
|
809
|
-
|
761
|
+
|
810
762
|
|
811
763
|
|
812
764
|
|
6
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
|
3
|
-
java初心者です。
|
3
|
+
プログラミング、java共に初心者です。
|
4
4
|
|
5
5
|
課題で、従業員の管理システムというものを作っており、
|
6
6
|
|
5
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -208,7 +208,7 @@
|
|
208
208
|
|
209
209
|
```
|
210
210
|
|
211
|
-
###該当のソースコード(MySer
|
211
|
+
###該当のソースコード(MyServlet_busyo_insert)
|
212
212
|
|
213
213
|
```lang-言語名
|
214
214
|
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -578,7 +578,7 @@
|
|
578
578
|
|
579
579
|
|
580
580
|
|
581
|
-
###該当のソースコード(
|
581
|
+
###該当のソースコード(JSP)
|
582
582
|
|
583
583
|
```lang-言語名
|
584
584
|
|
3
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
###該当のソースコード(My_Servlet_busyo_init)
|
40
40
|
|
41
|
-
|
41
|
+
```lang-言語名
|
42
42
|
|
43
43
|
package seminar;
|
44
44
|
|
@@ -206,11 +206,11 @@
|
|
206
206
|
|
207
207
|
}
|
208
208
|
|
209
|
-
|
209
|
+
```
|
210
210
|
|
211
211
|
###該当のソースコード(MySerblet_busyo_insert)
|
212
212
|
|
213
|
-
|
213
|
+
```lang-言語名
|
214
214
|
|
215
215
|
package seminar;
|
216
216
|
|
@@ -418,10 +418,12 @@
|
|
418
418
|
|
419
419
|
}
|
420
420
|
|
421
|
-
|
421
|
+
```
|
422
422
|
|
423
423
|
###該当のソースコード(Class DeptBean)
|
424
424
|
|
425
|
+
```lang-言語名
|
426
|
+
|
425
427
|
package seminar;
|
426
428
|
|
427
429
|
|
@@ -488,10 +490,12 @@
|
|
488
490
|
|
489
491
|
|
490
492
|
|
491
|
-
|
493
|
+
```
|
492
494
|
|
493
495
|
###該当のソースコード(class Uty)
|
494
496
|
|
497
|
+
```lang-言語名
|
498
|
+
|
495
499
|
package seminar;
|
496
500
|
|
497
501
|
|
@@ -570,11 +574,203 @@
|
|
570
574
|
|
571
575
|
|
572
576
|
|
573
|
-
|
577
|
+
```
|
578
|
+
|
579
|
+
|
580
|
+
|
574
|
-
|
581
|
+
###該当のソースコード(class Uty)
|
582
|
+
|
575
|
-
|
583
|
+
```lang-言語名
|
584
|
+
|
585
|
+
|
586
|
+
|
576
|
-
|
587
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
588
|
+
|
577
|
-
|
589
|
+
pageEncoding="UTF-8"%>
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
<%@page import="java.util.ArrayList"%>
|
594
|
+
|
595
|
+
<%@page import="seminar.EmpBean"%>
|
596
|
+
|
597
|
+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
598
|
+
|
599
|
+
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
606
|
+
|
607
|
+
<html>
|
608
|
+
|
609
|
+
<head>
|
610
|
+
|
611
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
612
|
+
|
613
|
+
<title>社員情報管理システム</title>
|
614
|
+
|
615
|
+
</head>
|
616
|
+
|
617
|
+
<body>
|
618
|
+
|
619
|
+
<form method="post" action="MyServlet_busyo_insert">
|
620
|
+
|
621
|
+
<input type="hidden" name="touroku" value="true">
|
622
|
+
|
623
|
+
<div style="wideth:80%; padding:1px; background-color:lightskyblue;">
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
<h1>社員情報管理システム:部署メンテ画面</h1>
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
</div>
|
632
|
+
|
633
|
+
<br><br>
|
634
|
+
|
635
|
+
<center>
|
636
|
+
|
637
|
+
<table>
|
638
|
+
|
639
|
+
<tr>
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
<td>部署コード</td>
|
644
|
+
|
645
|
+
<td><input type="text" name="deptno" id = "textforscb3" ></td>
|
646
|
+
|
647
|
+
<td width = 30>
|
648
|
+
|
649
|
+
<td><button type="submit" name="touroku" style="background-color:steelblue;;width:170px;height:30px"><font color="#fffaf"> 登 録</font></button></td>
|
650
|
+
|
651
|
+
</tr>
|
652
|
+
|
653
|
+
<tr>
|
654
|
+
|
655
|
+
<td>部署名</td>
|
656
|
+
|
657
|
+
<td> <input type="text" name="deptname"></td>
|
658
|
+
|
659
|
+
<td width = 30>
|
660
|
+
|
661
|
+
<td><button type="submit" style="background-color:steelblue;;width:170px;height:30px"><font color="#fffaf">変 更</font></button></td>
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
</tr>
|
668
|
+
|
669
|
+
</table>
|
670
|
+
|
671
|
+
</center>
|
672
|
+
|
673
|
+
</form>
|
674
|
+
|
675
|
+
<br>
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
<form method="post" action="MyServlet_busyo_init">
|
682
|
+
|
683
|
+
<center>
|
684
|
+
|
685
|
+
<div style="height: 290px; width: 400px; overflow-y: scroll;">
|
686
|
+
|
687
|
+
<table border=0 height="300" width="350" bgcolor="#f5f5f5">
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
<tr bgcolor="#4169e1">
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
<th></th>
|
696
|
+
|
697
|
+
<th width="2">部署コード</th>
|
698
|
+
|
699
|
+
<th width="30">部署名</th>
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
<c:forEach var="dept" items="${depts}">
|
706
|
+
|
707
|
+
<tr>
|
708
|
+
|
709
|
+
<td style = "width:3px">
|
710
|
+
|
711
|
+
<input type="checkbox" class="ck" onclick="connecttext('textforscb3',this.checked);" /></td>
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
<td>${dept.deptno}</td>
|
722
|
+
|
723
|
+
<td>${dept.deptname}</td>
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
</tr>
|
728
|
+
|
729
|
+
</c:forEach>
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
</table>
|
734
|
+
|
735
|
+
</div>
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
</center>
|
740
|
+
|
741
|
+
</form>
|
742
|
+
|
743
|
+
|
744
|
+
|
745
|
+
|
746
|
+
|
747
|
+
<br>
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
<DIV align="right" style="margin-right:160px">
|
754
|
+
|
755
|
+
<button type="submit" style="background-color:steelblue;;width:170px;height:30px;margin-right:150px;"><font color="#fffaf">削 除</font></button>
|
756
|
+
|
757
|
+
</Div>
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
|
762
|
+
|
763
|
+
</body>
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
</html>
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
```
|
578
774
|
|
579
775
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
580
776
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,9 +36,7 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
###該当のソースコード
|
40
|
-
|
41
|
-
My_Servlet_busyo_init
|
39
|
+
###該当のソースコード(My_Servlet_busyo_init)
|
42
40
|
|
43
41
|
|
44
42
|
|
@@ -210,11 +208,7 @@
|
|
210
208
|
|
211
209
|
|
212
210
|
|
213
|
-
###該当のソースコード
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
211
|
+
###該当のソースコード(MySerblet_busyo_insert)
|
218
212
|
|
219
213
|
|
220
214
|
|
@@ -426,7 +420,7 @@
|
|
426
420
|
|
427
421
|
|
428
422
|
|
429
|
-
###該当のソースコード
|
423
|
+
###該当のソースコード(Class DeptBean)
|
430
424
|
|
431
425
|
package seminar;
|
432
426
|
|
@@ -496,7 +490,7 @@
|
|
496
490
|
|
497
491
|
|
498
492
|
|
499
|
-
###該当のソースコード
|
493
|
+
###該当のソースコード(class Uty)
|
500
494
|
|
501
495
|
package seminar;
|
502
496
|
|
@@ -620,7 +614,7 @@
|
|
620
614
|
|
621
615
|
|
622
616
|
|
623
|
-
|
617
|
+
javaのことがまだ全然理解できておらず、至らない点も多々ございます。
|
624
618
|
|
625
619
|
拙い説明で本当に申し訳ございませんが、宜しければどなたかご教授頂ければ幸いです。
|
626
620
|
|
1
補足情報を入力し忘れましたすみません…
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,562 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
###該当のソースコード
|
40
|
+
|
41
|
+
My_Servlet_busyo_init
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
package seminar;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
import java.io.IOException;
|
50
|
+
|
51
|
+
import java.sql.Connection;
|
52
|
+
|
53
|
+
import java.sql.DriverManager;
|
54
|
+
|
55
|
+
import java.sql.ResultSet;
|
56
|
+
|
57
|
+
import java.sql.Statement;
|
58
|
+
|
59
|
+
import java.util.ArrayList;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
import javax.servlet.RequestDispatcher;
|
64
|
+
|
65
|
+
import javax.servlet.ServletException;
|
66
|
+
|
67
|
+
import javax.servlet.http.HttpServlet;
|
68
|
+
|
69
|
+
import javax.servlet.http.HttpServletRequest;
|
70
|
+
|
71
|
+
import javax.servlet.http.HttpServletResponse;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public class MyServlet_busyo_init extends HttpServlet {
|
76
|
+
|
77
|
+
private static final long serialVersionUID = 1L;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public MyServlet_busyo_init() {
|
82
|
+
|
83
|
+
super();
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
92
|
+
|
93
|
+
throws ServletException, IOException {
|
94
|
+
|
95
|
+
String driver = "org.postgresql.Driver";
|
96
|
+
|
97
|
+
String url = "jdbc:postgresql://localhost:5432/postgres";
|
98
|
+
|
99
|
+
String user = "postgres";
|
100
|
+
|
101
|
+
//String pwd =
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
String sql_dept = "Select * from DEPT order by dept_no";
|
106
|
+
|
107
|
+
Connection conn = null;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
request.setCharacterEncoding("UTF-8");
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
try {
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
Class.forName(driver);
|
124
|
+
|
125
|
+
conn = DriverManager.getConnection(url, user, pwd);
|
126
|
+
|
127
|
+
Statement stmt = conn.createStatement();
|
128
|
+
|
129
|
+
ResultSet rs = stmt.executeQuery(sql_dept);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
ArrayList<DeptBean> dept_list = new ArrayList<DeptBean>();
|
134
|
+
|
135
|
+
while (rs.next()) {
|
136
|
+
|
137
|
+
String dept_no = rs.getString("DEPT_NO");
|
138
|
+
|
139
|
+
String dept_name = rs.getString("DEPT_NAME");
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
//
|
144
|
+
|
145
|
+
DeptBean bean = new DeptBean();
|
146
|
+
|
147
|
+
bean.setDeptno(dept_no);
|
148
|
+
|
149
|
+
bean.setDeptname(dept_name);
|
150
|
+
|
151
|
+
//
|
152
|
+
|
153
|
+
dept_list.add(bean);
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
//
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
request.setAttribute("depts", dept_list);
|
162
|
+
|
163
|
+
RequestDispatcher rd = request.getRequestDispatcher("jsp03.jsp");
|
164
|
+
|
165
|
+
rd.forward(request, response);
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
} catch (Exception ex) {
|
170
|
+
|
171
|
+
ex.printStackTrace();
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
finally {
|
178
|
+
|
179
|
+
try {
|
180
|
+
|
181
|
+
conn.close();
|
182
|
+
|
183
|
+
} catch (Exception ex) {
|
184
|
+
|
185
|
+
;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
200
|
+
|
201
|
+
throws ServletException, IOException {
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
doGet(request, response);
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
###該当のソースコード
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
//MyServlet_busyo_insert
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
package seminar;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
import java.io.IOException;
|
226
|
+
|
227
|
+
import java.sql.Connection;
|
228
|
+
|
229
|
+
import java.sql.PreparedStatement;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
import javax.servlet.RequestDispatcher;
|
234
|
+
|
235
|
+
import javax.servlet.ServletException;
|
236
|
+
|
237
|
+
import javax.servlet.http.HttpServlet;
|
238
|
+
|
239
|
+
import javax.servlet.http.HttpServletRequest;
|
240
|
+
|
241
|
+
import javax.servlet.http.HttpServletResponse;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
public class MyServlet_busyo_insert extends HttpServlet {
|
246
|
+
|
247
|
+
private static final long serialVersionUID = 1L;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
public MyServlet_busyo_insert() {
|
252
|
+
|
253
|
+
super();
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
262
|
+
|
263
|
+
throws ServletException, IOException {
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
Connection conn = null;
|
268
|
+
|
269
|
+
String sql = "insert into (DEPT_NO,DEPT_NAME)values(?, ?)";
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
try {
|
274
|
+
|
275
|
+
if (request.getCharacterEncoding() == null) {
|
276
|
+
|
277
|
+
request.setCharacterEncoding("UTF-8");
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
String pm_dept_no = request.getParameter("deptno");
|
284
|
+
|
285
|
+
String pm_dept_name = request.getParameter("deptname");
|
286
|
+
|
287
|
+
String tourokuFlag = request.getParameter("touroku");
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
DeptBean bean = new DeptBean();
|
292
|
+
|
293
|
+
bean.setDeptno(pm_dept_no);
|
294
|
+
|
295
|
+
bean.setDeptname(pm_dept_name);
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
boolean is_error = false;
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
if (tourokuFlag != null) {
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
if (bean.getDeptno() == null ||
|
308
|
+
|
309
|
+
bean.getDeptname() == null ||
|
310
|
+
|
311
|
+
bean.getDeptno().trim().equals("")||
|
312
|
+
|
313
|
+
bean.getDeptname().trim().equals("")
|
314
|
+
|
315
|
+
) {
|
316
|
+
|
317
|
+
is_error = true;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
request.setAttribute("dept", bean);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
String jsp_page = "jsp03.jsp";
|
328
|
+
|
329
|
+
if (is_error) {
|
330
|
+
|
331
|
+
jsp_page = "jsp03.jsp";
|
332
|
+
|
333
|
+
request.setAttribute("err_msg", "データが全て入力されていません");
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
RequestDispatcher rd = request.getRequestDispatcher(jsp_page);
|
338
|
+
|
339
|
+
rd.forward(request, response);
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
conn = Uty.getConnection();
|
348
|
+
|
349
|
+
PreparedStatement ppst = conn.prepareStatement(sql);
|
350
|
+
|
351
|
+
ppst.setString(1,bean.getDeptno());
|
352
|
+
|
353
|
+
ppst.setString(2,bean.getDeptname());
|
354
|
+
|
355
|
+
int count = ppst.executeUpdate();
|
356
|
+
|
357
|
+
conn.close();
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
String msg = "追加が完了しました";
|
362
|
+
|
363
|
+
if(count < 1){
|
364
|
+
|
365
|
+
msg = "追加できませんでした";
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
request.setAttribute("dept",bean);
|
372
|
+
|
373
|
+
request.setAttribute("err_msg",msg);
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
RequestDispatcher rd = request.getRequestDispatcher("jsp03.jsp");
|
378
|
+
|
379
|
+
rd.forward(request,response);
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
catch (Exception ex) {
|
388
|
+
|
389
|
+
ex.printStackTrace();
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
finally {
|
394
|
+
|
395
|
+
try {
|
396
|
+
|
397
|
+
conn.close();
|
398
|
+
|
399
|
+
} catch (Exception ex) {
|
400
|
+
|
401
|
+
;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
414
|
+
|
415
|
+
throws ServletException, IOException {
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
doGet(request, response);
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
###該当のソースコード
|
430
|
+
|
431
|
+
package seminar;
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
public class DeptBean{
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
private String m_dept_no = "";
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
public String getDeptno() {
|
446
|
+
|
447
|
+
return this.m_dept_no;
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
public void setDeptno(String deptno) {
|
456
|
+
|
457
|
+
this.m_dept_no = deptno;
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
}
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
private String m_dept_name = "";
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
public String getDeptname() {
|
470
|
+
|
471
|
+
return this.m_dept_name;
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
public void setDeptname(String deptname) {
|
480
|
+
|
481
|
+
this.m_dept_name = deptname;
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
}
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
###該当のソースコード
|
500
|
+
|
501
|
+
package seminar;
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
import java.sql.Connection;
|
506
|
+
|
507
|
+
import java.sql.ResultSet;
|
508
|
+
|
509
|
+
import java.sql.SQLException;
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
import javax.naming.Context;
|
514
|
+
|
515
|
+
import javax.naming.NamingException;
|
516
|
+
|
517
|
+
import javax.sql.DataSource;
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
public class Uty {
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
public static Connection getConnection() throws NamingException, SQLException{
|
528
|
+
|
529
|
+
String judi_url = "java:comp/env/jdbc/sample";
|
530
|
+
|
531
|
+
Context ctx = new javax.naming.InitialContext();
|
532
|
+
|
533
|
+
DataSource ds = (javax.sql.DataSource)ctx.lookup(judi_url);
|
534
|
+
|
535
|
+
Connection conn =ds.getConnection();
|
536
|
+
|
537
|
+
return conn;
|
538
|
+
|
539
|
+
}
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
public static void setEmpBeanFromRs(EmpBean bean,ResultSet rs) throws SQLException{
|
544
|
+
|
545
|
+
bean.setEmpno(rs.getString("EMP_NO"));
|
546
|
+
|
547
|
+
bean.setDeptno(rs.getString("DEPT_NO"));
|
548
|
+
|
549
|
+
bean.setEmpname(rs.getString("EMP_NAME"));
|
550
|
+
|
551
|
+
bean.setEmpkana(rs.getString("EMP_KANA"));
|
552
|
+
|
553
|
+
bean.setAge(rs.getInt("AGE"));
|
554
|
+
|
555
|
+
bean.setGender(rs.getInt("GENDER"));
|
556
|
+
|
557
|
+
bean.setRemarks(rs.getString("REMARKS"));
|
558
|
+
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
public static void setDeptBeanFromRs(DeptBean bean,ResultSet rs) throws SQLException{
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
bean.setDeptno(rs.getString("DEPT_NO"));
|
568
|
+
|
569
|
+
bean.setDeptname(rs.getString("DEPT_NAME"));
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
}
|
574
|
+
|
575
|
+
}
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
###補足情報(言語/FW/ツール等のバージョンなど)
|
586
|
+
|
31
587
|
MyServlet_initが初期表示のサーブレット(ポスグレからデータを引っ張ってきて表示)
|
32
588
|
|
33
589
|
MyServlet_insertが空白判定と追加の処理
|
@@ -36,566 +592,36 @@
|
|
36
592
|
|
37
593
|
|
38
594
|
|
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
|
-
import javax.servlet.http.HttpServletRequest;
|
74
|
-
|
75
|
-
import javax.servlet.http.HttpServletResponse;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
public class MyServlet_busyo_init extends HttpServlet {
|
80
|
-
|
81
|
-
private static final long serialVersionUID = 1L;
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
public MyServlet_busyo_init() {
|
86
|
-
|
87
|
-
super();
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
96
|
-
|
97
|
-
throws ServletException, IOException {
|
98
|
-
|
99
|
-
String driver = "org.postgresql.Driver";
|
100
|
-
|
101
|
-
String url = "jdbc:postgresql://localhost:5432/postgres";
|
102
|
-
|
103
|
-
String user = "postgres";
|
104
|
-
|
105
|
-
//String pwd =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
String sql_dept = "Select * from DEPT order by dept_no";
|
110
|
-
|
111
|
-
Connection conn = null;
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
request.setCharacterEncoding("UTF-8");
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
try {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
Class.forName(driver);
|
128
|
-
|
129
|
-
conn = DriverManager.getConnection(url, user, pwd);
|
130
|
-
|
131
|
-
Statement stmt = conn.createStatement();
|
132
|
-
|
133
|
-
ResultSet rs = stmt.executeQuery(sql_dept);
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
ArrayList<DeptBean> dept_list = new ArrayList<DeptBean>();
|
138
|
-
|
139
|
-
while (rs.next()) {
|
140
|
-
|
141
|
-
String dept_no = rs.getString("DEPT_NO");
|
142
|
-
|
143
|
-
String dept_name = rs.getString("DEPT_NAME");
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
//
|
148
|
-
|
149
|
-
DeptBean bean = new DeptBean();
|
150
|
-
|
151
|
-
bean.setDeptno(dept_no);
|
152
|
-
|
153
|
-
bean.setDeptname(dept_name);
|
154
|
-
|
155
|
-
//
|
156
|
-
|
157
|
-
dept_list.add(bean);
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
//
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
request.setAttribute("depts", dept_list);
|
166
|
-
|
167
|
-
RequestDispatcher rd = request.getRequestDispatcher("jsp03.jsp");
|
168
|
-
|
169
|
-
rd.forward(request, response);
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
} catch (Exception ex) {
|
174
|
-
|
175
|
-
ex.printStackTrace();
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
finally {
|
182
|
-
|
183
|
-
try {
|
184
|
-
|
185
|
-
conn.close();
|
186
|
-
|
187
|
-
} catch (Exception ex) {
|
188
|
-
|
189
|
-
;
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
204
|
-
|
205
|
-
throws ServletException, IOException {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
doGet(request, response);
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
###該当のソースコード
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
//MyServlet_busyo_insert
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
package seminar;
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
import java.io.IOException;
|
230
|
-
|
231
|
-
import java.sql.Connection;
|
232
|
-
|
233
|
-
import java.sql.PreparedStatement;
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
import javax.servlet.RequestDispatcher;
|
238
|
-
|
239
|
-
import javax.servlet.ServletException;
|
240
|
-
|
241
|
-
import javax.servlet.http.HttpServlet;
|
242
|
-
|
243
|
-
import javax.servlet.http.HttpServletRequest;
|
244
|
-
|
245
|
-
import javax.servlet.http.HttpServletResponse;
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
public class MyServlet_busyo_insert extends HttpServlet {
|
250
|
-
|
251
|
-
private static final long serialVersionUID = 1L;
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
public MyServlet_busyo_insert() {
|
256
|
-
|
257
|
-
super();
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
266
|
-
|
267
|
-
throws ServletException, IOException {
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
Connection conn = null;
|
272
|
-
|
273
|
-
String sql = "insert into (DEPT_NO,DEPT_NAME)values(?, ?)";
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
try {
|
278
|
-
|
279
|
-
if (request.getCharacterEncoding() == null) {
|
280
|
-
|
281
|
-
request.setCharacterEncoding("UTF-8");
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
String pm_dept_no = request.getParameter("deptno");
|
288
|
-
|
289
|
-
String pm_dept_name = request.getParameter("deptname");
|
290
|
-
|
291
|
-
String tourokuFlag = request.getParameter("touroku");
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
DeptBean bean = new DeptBean();
|
296
|
-
|
297
|
-
bean.setDeptno(pm_dept_no);
|
298
|
-
|
299
|
-
bean.setDeptname(pm_dept_name);
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
boolean is_error = false;
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
if (tourokuFlag != null) {
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
if (bean.getDeptno() == null ||
|
312
|
-
|
313
|
-
bean.getDeptname() == null ||
|
314
|
-
|
315
|
-
bean.getDeptno().trim().equals("")||
|
316
|
-
|
317
|
-
bean.getDeptname().trim().equals("")
|
318
|
-
|
319
|
-
) {
|
320
|
-
|
321
|
-
is_error = true;
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
request.setAttribute("dept", bean);
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
String jsp_page = "jsp03.jsp";
|
332
|
-
|
333
|
-
if (is_error) {
|
334
|
-
|
335
|
-
jsp_page = "jsp03.jsp";
|
336
|
-
|
337
|
-
request.setAttribute("err_msg", "データが全て入力されていません");
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
RequestDispatcher rd = request.getRequestDispatcher(jsp_page);
|
342
|
-
|
343
|
-
rd.forward(request, response);
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
conn = Uty.getConnection();
|
352
|
-
|
353
|
-
PreparedStatement ppst = conn.prepareStatement(sql);
|
354
|
-
|
355
|
-
ppst.setString(1,bean.getDeptno());
|
356
|
-
|
357
|
-
ppst.setString(2,bean.getDeptname());
|
358
|
-
|
359
|
-
int count = ppst.executeUpdate();
|
360
|
-
|
361
|
-
conn.close();
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
String msg = "追加が完了しました";
|
366
|
-
|
367
|
-
if(count < 1){
|
368
|
-
|
369
|
-
msg = "追加できませんでした";
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
request.setAttribute("dept",bean);
|
376
|
-
|
377
|
-
request.setAttribute("err_msg",msg);
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
RequestDispatcher rd = request.getRequestDispatcher("jsp03.jsp");
|
382
|
-
|
383
|
-
rd.forward(request,response);
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
catch (Exception ex) {
|
392
|
-
|
393
|
-
ex.printStackTrace();
|
394
|
-
|
395
|
-
}
|
396
|
-
|
397
|
-
finally {
|
398
|
-
|
399
|
-
try {
|
400
|
-
|
401
|
-
conn.close();
|
402
|
-
|
403
|
-
} catch (Exception ex) {
|
404
|
-
|
405
|
-
;
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
}
|
410
|
-
|
411
|
-
}
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
418
|
-
|
419
|
-
throws ServletException, IOException {
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
doGet(request, response);
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
}
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
###該当のソースコード
|
434
|
-
|
435
|
-
package seminar;
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
public class DeptBean{
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
private String m_dept_no = "";
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
public String getDeptno() {
|
450
|
-
|
451
|
-
return this.m_dept_no;
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
public void setDeptno(String deptno) {
|
460
|
-
|
461
|
-
this.m_dept_no = deptno;
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
private String m_dept_name = "";
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
public String getDeptname() {
|
474
|
-
|
475
|
-
return this.m_dept_name;
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
public void setDeptname(String deptname) {
|
484
|
-
|
485
|
-
this.m_dept_name = deptname;
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
}
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
}
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
###該当のソースコード
|
504
|
-
|
505
|
-
package seminar;
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
import java.sql.Connection;
|
510
|
-
|
511
|
-
import java.sql.ResultSet;
|
512
|
-
|
513
|
-
import java.sql.SQLException;
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
import javax.naming.Context;
|
518
|
-
|
519
|
-
import javax.naming.NamingException;
|
520
|
-
|
521
|
-
import javax.sql.DataSource;
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
public class Uty {
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
public static Connection getConnection() throws NamingException, SQLException{
|
532
|
-
|
533
|
-
String judi_url = "java:comp/env/jdbc/sample";
|
534
|
-
|
535
|
-
Context ctx = new javax.naming.InitialContext();
|
536
|
-
|
537
|
-
DataSource ds = (javax.sql.DataSource)ctx.lookup(judi_url);
|
538
|
-
|
539
|
-
Connection conn =ds.getConnection();
|
540
|
-
|
541
|
-
return conn;
|
542
|
-
|
543
|
-
}
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
public static void setEmpBeanFromRs(EmpBean bean,ResultSet rs) throws SQLException{
|
548
|
-
|
549
|
-
bean.setEmpno(rs.getString("EMP_NO"));
|
550
|
-
|
551
|
-
bean.setDeptno(rs.getString("DEPT_NO"));
|
552
|
-
|
553
|
-
bean.setEmpname(rs.getString("EMP_NAME"));
|
554
|
-
|
555
|
-
bean.setEmpkana(rs.getString("EMP_KANA"));
|
556
|
-
|
557
|
-
bean.setAge(rs.getInt("AGE"));
|
558
|
-
|
559
|
-
bean.setGender(rs.getInt("GENDER"));
|
560
|
-
|
561
|
-
bean.setRemarks(rs.getString("REMARKS"));
|
562
|
-
|
563
|
-
}
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
public static void setDeptBeanFromRs(DeptBean bean,ResultSet rs) throws SQLException{
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
bean.setDeptno(rs.getString("DEPT_NO"));
|
572
|
-
|
573
|
-
bean.setDeptname(rs.getString("DEPT_NAME"));
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
}
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
ここにご自身が実行したソースコードを書いてください
|
588
|
-
|
589
|
-
```
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
###試したこと
|
594
|
-
|
595
|
-
課題に対してアプローチしたことを記載してください
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
600
|
-
|
601
|
-
より詳細な情報
|
595
|
+
開発環境はeclipse,サーバーはTomcat6を使用しています。
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
部署名と部署コードのデータはPostgreSQLでテーブルを作成し、その中にデータが入っており、
|
604
|
+
|
605
|
+
そのデータを引っ張ってきている形です。
|
606
|
+
|
607
|
+
テーブル情報は下記の通りです
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
テーブル名 : DEPT
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
カラム名 カラム名 定義
|
616
|
+
|
617
|
+
部署コード DEPT_NO CHAR(2) PK
|
618
|
+
|
619
|
+
部署名 DEPT_NAME VARCHAR(20)
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
拙い説明で本当に申し訳ございませんが、宜しければどなたかご教授頂ければ幸いです。
|
626
|
+
|
627
|
+
宜しくお願い致します。
|