質問編集履歴
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -586,6 +586,14 @@
|
|
586
586
|
|
587
587
|
String sql = "SELECT * FROM Information WHERE NO ="+No+"AND (NAME LIKE '"+Name+"%' OR NAME LIKE '%"+Name+"')";
|
588
588
|
|
589
|
+
~中略~
|
590
|
+
|
591
|
+
}else if(No != "" && Name == "") {
|
592
|
+
|
593
|
+
try {
|
594
|
+
|
595
|
+
String sql = "SELECT * FROM Information WHERE NO ="+No;
|
596
|
+
|
589
597
|
conn = DBManager.getConnection();
|
590
598
|
|
591
599
|
smt = conn.createStatement();
|
@@ -594,13 +602,19 @@
|
|
594
602
|
|
595
603
|
List list = new ArrayList();
|
596
604
|
|
605
|
+
DataBase db = new DataBase();
|
606
|
+
|
607
|
+
|
608
|
+
|
597
609
|
//画面表示させるためにLISTに格納
|
598
610
|
|
599
611
|
while(rs.next()) {
|
600
612
|
|
613
|
+
|
614
|
+
|
601
615
|
~中略~
|
602
616
|
|
603
|
-
db.setName(
|
617
|
+
db.setName(rs.getString("name"));
|
604
618
|
|
605
619
|
|
606
620
|
|
@@ -608,6 +622,8 @@
|
|
608
622
|
|
609
623
|
list.add(db);
|
610
624
|
|
625
|
+
|
626
|
+
|
611
627
|
}
|
612
628
|
|
613
629
|
if(list.isEmpty()) {
|
@@ -616,20 +632,26 @@
|
|
616
632
|
|
617
633
|
}
|
618
634
|
|
619
|
-
request.setAttribute("list", list);
|
635
|
+
request.setAttribute("list", list);
|
636
|
+
|
620
|
-
|
637
|
+
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);//◆◆◆
|
638
|
+
|
639
|
+
return;
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
}catch(SQLException e) {
|
648
|
+
|
621
|
-
request.getRequestDispatcher("/jsp/
|
649
|
+
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
622
650
|
|
623
651
|
return;
|
624
652
|
|
625
653
|
|
626
654
|
|
627
|
-
}catch(SQLException e) {
|
628
|
-
|
629
|
-
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
630
|
-
|
631
|
-
return;
|
632
|
-
|
633
655
|
|
634
656
|
|
635
657
|
}finally {
|
@@ -650,163 +672,7 @@
|
|
650
672
|
|
651
673
|
|
652
674
|
|
653
|
-
|
654
|
-
|
655
|
-
}else if(No != "" && Name == "") {
|
656
|
-
|
657
|
-
try {
|
658
|
-
|
659
|
-
String sql = "SELECT * FROM Information WHERE NO ="+No;
|
660
|
-
|
661
|
-
conn = DBManager.getConnection();
|
662
|
-
|
663
|
-
smt = conn.createStatement();
|
664
|
-
|
665
|
-
ResultSet rs = smt.executeQuery(sql);
|
666
|
-
|
667
|
-
List list = new ArrayList();
|
668
|
-
|
669
|
-
DataBase db = new DataBase();
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
//画面表示させるためにLISTに格納
|
674
|
-
|
675
|
-
while(rs.next()) {
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
675
|
+
~中略~
|
680
|
-
|
681
|
-
db.setName(rs.getString("name"));
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
list.add(db);
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
}
|
692
|
-
|
693
|
-
if(list.isEmpty()) {
|
694
|
-
|
695
|
-
throw new SQLException();
|
696
|
-
|
697
|
-
}
|
698
|
-
|
699
|
-
request.setAttribute("list", list);
|
700
|
-
|
701
|
-
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);
|
702
|
-
|
703
|
-
return;
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
}catch(SQLException e) {
|
712
|
-
|
713
|
-
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);//◆◆◆
|
714
|
-
|
715
|
-
return;
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
}finally {
|
722
|
-
|
723
|
-
if(smt != null) {
|
724
|
-
|
725
|
-
try {smt.close();}catch(SQLException ignore) {}
|
726
|
-
|
727
|
-
}
|
728
|
-
|
729
|
-
if(conn != null) {
|
730
|
-
|
731
|
-
try {conn.close();}catch(SQLException ignore) {}
|
732
|
-
|
733
|
-
}
|
734
|
-
|
735
|
-
}
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
}else if(No == "" && Name != "") {
|
742
|
-
|
743
|
-
//名前だけの検索
|
744
|
-
|
745
|
-
try {
|
746
|
-
|
747
|
-
String sql = "SELECT * FROM Information WHERE NAME LIKE '"+Name+"%' OR NAME LIKE '%"+Name+"'";
|
748
|
-
|
749
|
-
conn = DBManager.getConnection();
|
750
|
-
|
751
|
-
smt = conn.createStatement();
|
752
|
-
|
753
|
-
ResultSet rs = smt.executeQuery(sql);
|
754
|
-
|
755
|
-
List list = new ArrayList();
|
756
|
-
|
757
|
-
//画面表示させるためにLISTに格納
|
758
|
-
|
759
|
-
while(rs.next()) {
|
760
|
-
|
761
|
-
~中略~
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
list.add(db);
|
770
|
-
|
771
|
-
}
|
772
|
-
|
773
|
-
if(list.isEmpty()) {
|
774
|
-
|
775
|
-
throw new SQLException();
|
776
|
-
|
777
|
-
}
|
778
|
-
|
779
|
-
request.setAttribute("list", list);
|
780
|
-
|
781
|
-
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);
|
782
|
-
|
783
|
-
return;
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
}catch(SQLException e) {
|
788
|
-
|
789
|
-
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
790
|
-
|
791
|
-
return;
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
}finally {
|
796
|
-
|
797
|
-
if(smt != null) {
|
798
|
-
|
799
|
-
try {smt.close();}catch(SQLException ignore) {}
|
800
|
-
|
801
|
-
}
|
802
|
-
|
803
|
-
if(conn != null) {
|
804
|
-
|
805
|
-
try {conn.close();}catch(SQLException ignore) {}
|
806
|
-
|
807
|
-
}
|
808
|
-
|
809
|
-
}
|
810
676
|
|
811
677
|
|
812
678
|
|
2
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -513,3 +513,319 @@
|
|
513
513
|
</html>
|
514
514
|
|
515
515
|
```
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
追加です。エラーが出た文をまったく同じように書き直すことによって最初に出ていた箇所のエラーは無くなりました。しかし進んだ別の箇所で同じエラーが出ます。エラーが出ているのはSerchServlet.javaの115行目(◆マーク)です。
|
520
|
+
|
521
|
+
```servlet
|
522
|
+
|
523
|
+
package Look;
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
import java.io.IOException;
|
528
|
+
|
529
|
+
import java.sql.Connection;
|
530
|
+
|
531
|
+
import java.sql.ResultSet;
|
532
|
+
|
533
|
+
import java.sql.SQLException;
|
534
|
+
|
535
|
+
import java.sql.Statement;
|
536
|
+
|
537
|
+
import java.util.ArrayList;
|
538
|
+
|
539
|
+
import java.util.List;
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
import javax.servlet.ServletException;
|
544
|
+
|
545
|
+
import javax.servlet.http.HttpServlet;
|
546
|
+
|
547
|
+
import javax.servlet.http.HttpServletRequest;
|
548
|
+
|
549
|
+
import javax.servlet.http.HttpServletResponse;
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
public class SearchServlet extends HttpServlet {
|
556
|
+
|
557
|
+
private static final long serialVersionUID = 1L;
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
562
|
+
|
563
|
+
request.setCharacterEncoding("utf-8");
|
564
|
+
|
565
|
+
//受け取ったデータ
|
566
|
+
|
567
|
+
String No = request.getParameter("No");
|
568
|
+
|
569
|
+
String Name = request.getParameter("Name");
|
570
|
+
|
571
|
+
//接続準備
|
572
|
+
|
573
|
+
Connection conn = null;
|
574
|
+
|
575
|
+
Statement smt = null;
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
//接続開始
|
580
|
+
|
581
|
+
//NOとNAME両方で検索
|
582
|
+
|
583
|
+
if(No != "" && Name != "") {
|
584
|
+
|
585
|
+
try {
|
586
|
+
|
587
|
+
String sql = "SELECT * FROM Information WHERE NO ="+No+"AND (NAME LIKE '"+Name+"%' OR NAME LIKE '%"+Name+"')";
|
588
|
+
|
589
|
+
conn = DBManager.getConnection();
|
590
|
+
|
591
|
+
smt = conn.createStatement();
|
592
|
+
|
593
|
+
ResultSet rs = smt.executeQuery(sql);
|
594
|
+
|
595
|
+
List list = new ArrayList();
|
596
|
+
|
597
|
+
//画面表示させるためにLISTに格納
|
598
|
+
|
599
|
+
while(rs.next()) {
|
600
|
+
|
601
|
+
~中略~
|
602
|
+
|
603
|
+
db.setName(Name);
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
list.add(db);
|
610
|
+
|
611
|
+
}
|
612
|
+
|
613
|
+
if(list.isEmpty()) {
|
614
|
+
|
615
|
+
throw new SQLException();
|
616
|
+
|
617
|
+
}
|
618
|
+
|
619
|
+
request.setAttribute("list", list);
|
620
|
+
|
621
|
+
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);
|
622
|
+
|
623
|
+
return;
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
}catch(SQLException e) {
|
628
|
+
|
629
|
+
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
630
|
+
|
631
|
+
return;
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
}finally {
|
636
|
+
|
637
|
+
if(smt != null) {
|
638
|
+
|
639
|
+
try {smt.close();}catch(SQLException ignore) {}
|
640
|
+
|
641
|
+
}
|
642
|
+
|
643
|
+
if(conn != null) {
|
644
|
+
|
645
|
+
try {conn.close();}catch(SQLException ignore) {}
|
646
|
+
|
647
|
+
}
|
648
|
+
|
649
|
+
}
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
}else if(No != "" && Name == "") {
|
656
|
+
|
657
|
+
try {
|
658
|
+
|
659
|
+
String sql = "SELECT * FROM Information WHERE NO ="+No;
|
660
|
+
|
661
|
+
conn = DBManager.getConnection();
|
662
|
+
|
663
|
+
smt = conn.createStatement();
|
664
|
+
|
665
|
+
ResultSet rs = smt.executeQuery(sql);
|
666
|
+
|
667
|
+
List list = new ArrayList();
|
668
|
+
|
669
|
+
DataBase db = new DataBase();
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
//画面表示させるためにLISTに格納
|
674
|
+
|
675
|
+
while(rs.next()) {
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
~中略~
|
680
|
+
|
681
|
+
db.setName(rs.getString("name"));
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
list.add(db);
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
}
|
692
|
+
|
693
|
+
if(list.isEmpty()) {
|
694
|
+
|
695
|
+
throw new SQLException();
|
696
|
+
|
697
|
+
}
|
698
|
+
|
699
|
+
request.setAttribute("list", list);
|
700
|
+
|
701
|
+
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);
|
702
|
+
|
703
|
+
return;
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
}catch(SQLException e) {
|
712
|
+
|
713
|
+
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);//◆◆◆
|
714
|
+
|
715
|
+
return;
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
}finally {
|
722
|
+
|
723
|
+
if(smt != null) {
|
724
|
+
|
725
|
+
try {smt.close();}catch(SQLException ignore) {}
|
726
|
+
|
727
|
+
}
|
728
|
+
|
729
|
+
if(conn != null) {
|
730
|
+
|
731
|
+
try {conn.close();}catch(SQLException ignore) {}
|
732
|
+
|
733
|
+
}
|
734
|
+
|
735
|
+
}
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
}else if(No == "" && Name != "") {
|
742
|
+
|
743
|
+
//名前だけの検索
|
744
|
+
|
745
|
+
try {
|
746
|
+
|
747
|
+
String sql = "SELECT * FROM Information WHERE NAME LIKE '"+Name+"%' OR NAME LIKE '%"+Name+"'";
|
748
|
+
|
749
|
+
conn = DBManager.getConnection();
|
750
|
+
|
751
|
+
smt = conn.createStatement();
|
752
|
+
|
753
|
+
ResultSet rs = smt.executeQuery(sql);
|
754
|
+
|
755
|
+
List list = new ArrayList();
|
756
|
+
|
757
|
+
//画面表示させるためにLISTに格納
|
758
|
+
|
759
|
+
while(rs.next()) {
|
760
|
+
|
761
|
+
~中略~
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
list.add(db);
|
770
|
+
|
771
|
+
}
|
772
|
+
|
773
|
+
if(list.isEmpty()) {
|
774
|
+
|
775
|
+
throw new SQLException();
|
776
|
+
|
777
|
+
}
|
778
|
+
|
779
|
+
request.setAttribute("list", list);
|
780
|
+
|
781
|
+
request.getRequestDispatcher("/jsp/Search.jsp").forward(request, response);
|
782
|
+
|
783
|
+
return;
|
784
|
+
|
785
|
+
|
786
|
+
|
787
|
+
}catch(SQLException e) {
|
788
|
+
|
789
|
+
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
790
|
+
|
791
|
+
return;
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
}finally {
|
796
|
+
|
797
|
+
if(smt != null) {
|
798
|
+
|
799
|
+
try {smt.close();}catch(SQLException ignore) {}
|
800
|
+
|
801
|
+
}
|
802
|
+
|
803
|
+
if(conn != null) {
|
804
|
+
|
805
|
+
try {conn.close();}catch(SQLException ignore) {}
|
806
|
+
|
807
|
+
}
|
808
|
+
|
809
|
+
}
|
810
|
+
|
811
|
+
|
812
|
+
|
813
|
+
}else {
|
814
|
+
|
815
|
+
//該当がない場合
|
816
|
+
|
817
|
+
request.getRequestDispatcher("/jsp/result.jsp").forward(request, response);
|
818
|
+
|
819
|
+
return;
|
820
|
+
|
821
|
+
}
|
822
|
+
|
823
|
+
}
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
}
|
828
|
+
|
829
|
+
|
830
|
+
|
831
|
+
```
|
1
コードの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
書いていないはずのメソッドでエラーが出たときの対処が知りたいです。
|
1
|
+
kod-書いていないはずのメソッドでエラーが出たときの対処が知りたいです。
|
test
CHANGED
@@ -395,3 +395,121 @@
|
|
395
395
|
}
|
396
396
|
|
397
397
|
```
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
```jsp
|
402
|
+
|
403
|
+
<%@ page language="java" contentType="text/html;" pageEncoding="UTF-8"%>
|
404
|
+
|
405
|
+
<%@ page import="java.util.List,Look.DataBase"%>
|
406
|
+
|
407
|
+
<!DOCTYPE html>
|
408
|
+
|
409
|
+
<html>
|
410
|
+
|
411
|
+
<head>
|
412
|
+
|
413
|
+
<meta charset="UTF-8">
|
414
|
+
|
415
|
+
<title>アンケートNo入力画面</title>
|
416
|
+
|
417
|
+
<link rel="stylesheet" href="CSS/Look.css">
|
418
|
+
|
419
|
+
</head>
|
420
|
+
|
421
|
+
<body>
|
422
|
+
|
423
|
+
<h1>アンケート一覧</h1>
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
<form method="post" action="/Look/SearchServlet">
|
428
|
+
|
429
|
+
<div id="div1">
|
430
|
+
|
431
|
+
<p>アンケートNO:<input type="text" name="No"></p>
|
432
|
+
|
433
|
+
<p>氏名:<input type="text" name="Name"></p>
|
434
|
+
|
435
|
+
</div>
|
436
|
+
|
437
|
+
<input type="submit" name="search" value="検索">
|
438
|
+
|
439
|
+
</form>
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
<div id="div2">
|
444
|
+
|
445
|
+
<form >
|
446
|
+
|
447
|
+
<input type="button" name="new" value="新規" onClick="">
|
448
|
+
|
449
|
+
</form>
|
450
|
+
|
451
|
+
</div>
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
<form method="POST" action="/Look/UpdateServlet">
|
456
|
+
|
457
|
+
<table>
|
458
|
+
|
459
|
+
<tr>
|
460
|
+
|
461
|
+
<th>アンケートNO</th>
|
462
|
+
|
463
|
+
<th>氏名</th>
|
464
|
+
|
465
|
+
<th></th>
|
466
|
+
|
467
|
+
<th></th>
|
468
|
+
|
469
|
+
</tr>
|
470
|
+
|
471
|
+
<%
|
472
|
+
|
473
|
+
List list = (List)request.getAttribute("list");
|
474
|
+
|
475
|
+
for(int i=0 ; i<list.size() ; i++){
|
476
|
+
|
477
|
+
DataBase db = (DataBase)list.get(i);
|
478
|
+
|
479
|
+
%>
|
480
|
+
|
481
|
+
<tr>
|
482
|
+
|
483
|
+
<td><%= db.getNo() %></td>
|
484
|
+
|
485
|
+
<td><%= db.getName() %></td>
|
486
|
+
|
487
|
+
<td>
|
488
|
+
|
489
|
+
<input type="submit" name="update" value="変更" >
|
490
|
+
|
491
|
+
<input type="hidden" name="flag" value="1">
|
492
|
+
|
493
|
+
<input type="hidden" name="hiddenNO" value="<%= db.getNo() %>">
|
494
|
+
|
495
|
+
</td>
|
496
|
+
|
497
|
+
<td>
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
</td>
|
502
|
+
|
503
|
+
</tr>
|
504
|
+
|
505
|
+
<% } %>
|
506
|
+
|
507
|
+
</table>
|
508
|
+
|
509
|
+
</form>
|
510
|
+
|
511
|
+
</body>
|
512
|
+
|
513
|
+
</html>
|
514
|
+
|
515
|
+
```
|