質問編集履歴
1
コードを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,74 @@
|
|
4
4
|
getattributeで点数(score)を保存し1問正解する事に+10し、jspで表示できるようにしたいです。
|
5
5
|
|
6
6
|
|
7
|
-
現在フィールドでscoreを保存しているDtoを初期化し行っているので、何問正解しようとあなたの点数は0点ですと出てしまいます
|
7
|
+
現在フィールドでscoreを保存しているDtoを初期化し行っているので、何問正解しようとあなたの点数は0点ですと出てしまいます
|
8
|
+
|
9
|
+
```Java
|
10
|
+
package jp.co.action.test;
|
11
|
+
|
12
|
+
import java.io.IOException;
|
13
|
+
import java.sql.Connection;
|
14
|
+
import java.sql.SQLException;
|
15
|
+
import java.util.ArrayList;
|
16
|
+
|
17
|
+
import javax.servlet.ServletException;
|
18
|
+
import javax.servlet.http.HttpServlet;
|
19
|
+
import javax.servlet.http.HttpServletRequest;
|
20
|
+
import javax.servlet.http.HttpServletResponse;
|
21
|
+
import javax.servlet.http.HttpSession;
|
22
|
+
|
23
|
+
import jp.co.db.DbDao;
|
24
|
+
import jp.co.db.DbDto;
|
25
|
+
import jp.co.db.DbUtility;
|
26
|
+
import jp.co.db.TestDto;
|
27
|
+
|
28
|
+
public class TestResultServlet extends HttpServlet{
|
29
|
+
//ArrayListの生成
|
30
|
+
|
31
|
+
|
32
|
+
public static ArrayList<DbDto> tesres = new ArrayList<jp.co.db.DbDto>();
|
33
|
+
|
34
|
+
protected void service(HttpServletRequest req, HttpServletResponse res)
|
35
|
+
throws ServletException, IOException {
|
36
|
+
|
37
|
+
HttpSession session = req.getSession();
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
req.setCharacterEncoding("UTF-8");
|
42
|
+
|
43
|
+
String answer = req.getParameter("answer");
|
44
|
+
|
45
|
+
try {
|
46
|
+
Connection con;
|
47
|
+
DbUtility db = new DbUtility();
|
48
|
+
Class.forName("com.mysql.jdbc.Driver");
|
49
|
+
con = db.con("jdbc:mysql://127.0.0.1:3306/rezodb?serverTimezone=UTC","rezouser" ,"Rezo_0000");
|
50
|
+
DbDao dao = new DbDao();
|
51
|
+
TestDto tesre = new TestDto();
|
52
|
+
|
53
|
+
//new DbDao().searchAll(con)
|
54
|
+
System.out.println(tesres.size());
|
55
|
+
|
56
|
+
req.setAttribute("answer", answer);
|
57
|
+
session.setAttribute("tesre", tesre);
|
58
|
+
|
59
|
+
|
60
|
+
tesres = dao.testAnswer(con);
|
61
|
+
|
62
|
+
for(int i = 0; i< tesres.size();i++) {
|
63
|
+
if(answer.equals(tesres.get(0).getWorddescription())) {
|
64
|
+
session.getAttribute("tesre");
|
65
|
+
tesre.setScore(tesre.getScore()+10);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
req.setAttribute("tesres", tesres);
|
69
|
+
|
70
|
+
req.getRequestDispatcher("testResult.jsp").forward(req, res);
|
71
|
+
|
72
|
+
}catch(SQLException | ClassNotFoundException e) {
|
73
|
+
e.printStackTrace();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
```
|