質問編集履歴

1

コードを追加しました

2018/06/13 18:16

投稿

mito_rafu168
mito_rafu168

スコア6

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,143 @@
11
11
 
12
12
 
13
13
  現在フィールドでscoreを保存しているDtoを初期化し行っているので、何問正解しようとあなたの点数は0点ですと出てしまいます
14
+
15
+
16
+
17
+ ```Java
18
+
19
+ package jp.co.action.test;
20
+
21
+
22
+
23
+ import java.io.IOException;
24
+
25
+ import java.sql.Connection;
26
+
27
+ import java.sql.SQLException;
28
+
29
+ import java.util.ArrayList;
30
+
31
+
32
+
33
+ import javax.servlet.ServletException;
34
+
35
+ import javax.servlet.http.HttpServlet;
36
+
37
+ import javax.servlet.http.HttpServletRequest;
38
+
39
+ import javax.servlet.http.HttpServletResponse;
40
+
41
+ import javax.servlet.http.HttpSession;
42
+
43
+
44
+
45
+ import jp.co.db.DbDao;
46
+
47
+ import jp.co.db.DbDto;
48
+
49
+ import jp.co.db.DbUtility;
50
+
51
+ import jp.co.db.TestDto;
52
+
53
+
54
+
55
+ public class TestResultServlet extends HttpServlet{
56
+
57
+ //ArrayListの生成
58
+
59
+
60
+
61
+
62
+
63
+ public static ArrayList<DbDto> tesres = new ArrayList<jp.co.db.DbDto>();
64
+
65
+
66
+
67
+ protected void service(HttpServletRequest req, HttpServletResponse res)
68
+
69
+ throws ServletException, IOException {
70
+
71
+
72
+
73
+ HttpSession session = req.getSession();
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ req.setCharacterEncoding("UTF-8");
82
+
83
+
84
+
85
+ String answer = req.getParameter("answer");
86
+
87
+
88
+
89
+ try {
90
+
91
+ Connection con;
92
+
93
+ DbUtility db = new DbUtility();
94
+
95
+ Class.forName("com.mysql.jdbc.Driver");
96
+
97
+ con = db.con("jdbc:mysql://127.0.0.1:3306/rezodb?serverTimezone=UTC","rezouser" ,"Rezo_0000");
98
+
99
+ DbDao dao = new DbDao();
100
+
101
+ TestDto tesre = new TestDto();
102
+
103
+
104
+
105
+ //new DbDao().searchAll(con)
106
+
107
+ System.out.println(tesres.size());
108
+
109
+
110
+
111
+ req.setAttribute("answer", answer);
112
+
113
+ session.setAttribute("tesre", tesre);
114
+
115
+
116
+
117
+
118
+
119
+ tesres = dao.testAnswer(con);
120
+
121
+
122
+
123
+ for(int i = 0; i< tesres.size();i++) {
124
+
125
+ if(answer.equals(tesres.get(0).getWorddescription())) {
126
+
127
+ session.getAttribute("tesre");
128
+
129
+ tesre.setScore(tesre.getScore()+10);
130
+
131
+ }
132
+
133
+ }
134
+
135
+ req.setAttribute("tesres", tesres);
136
+
137
+
138
+
139
+ req.getRequestDispatcher("testResult.jsp").forward(req, res);
140
+
141
+
142
+
143
+ }catch(SQLException | ClassNotFoundException e) {
144
+
145
+ e.printStackTrace();
146
+
147
+ }
148
+
149
+ }
150
+
151
+ }
152
+
153
+ ```