質問編集履歴
7
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Java servlet
|
1
|
+
Java servlet 簡易掲示板の値の保持
|
test
CHANGED
File without changes
|
6
アドバイスを受けて
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
```jsp
|
35
|
+
```jsp
|
36
36
|
|
37
37
|
|
38
38
|
|
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
```
|
71
|
+
```SiteEvent
|
72
72
|
|
73
73
|
package model;
|
74
74
|
|
@@ -126,7 +126,7 @@
|
|
126
126
|
|
127
127
|
|
128
128
|
|
129
|
-
```servlet
|
129
|
+
```servlet
|
130
130
|
|
131
131
|
package servlet;
|
132
132
|
|
5
アドバイスを受けて
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,9 +32,9 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
```
|
36
|
-
|
37
|
-
jsp(view)
|
35
|
+
```jsp(view)
|
36
|
+
|
37
|
+
|
38
38
|
|
39
39
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
40
40
|
|
@@ -68,11 +68,7 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
```
|
72
|
-
|
73
|
-
java(model)
|
71
|
+
```java(model)SiteEvent
|
74
|
-
|
75
|
-
SiteEvent
|
76
72
|
|
77
73
|
package model;
|
78
74
|
|
@@ -104,9 +100,7 @@
|
|
104
100
|
|
105
101
|
```
|
106
102
|
|
107
|
-
```
|
108
|
-
|
109
|
-
SiteEventLogic
|
103
|
+
```SiteEventLogic
|
110
104
|
|
111
105
|
package model;
|
112
106
|
|
@@ -132,9 +126,7 @@
|
|
132
126
|
|
133
127
|
|
134
128
|
|
135
|
-
```
|
136
|
-
|
137
|
-
servlet(contorol)
|
129
|
+
```servlet(contorol)
|
138
130
|
|
139
131
|
package servlet;
|
140
132
|
|
4
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,9 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
```
|
36
|
+
|
35
|
-
|
37
|
+
jsp(view)
|
36
38
|
|
37
39
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
38
40
|
|
@@ -62,11 +64,15 @@
|
|
62
64
|
|
63
65
|
</html>
|
64
66
|
|
65
|
-
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
|
66
|
-
|
71
|
+
```
|
72
|
+
|
67
|
-
|
73
|
+
java(model)
|
68
|
-
|
74
|
+
|
69
|
-
|
75
|
+
SiteEvent
|
70
76
|
|
71
77
|
package model;
|
72
78
|
|
@@ -96,9 +102,11 @@
|
|
96
102
|
|
97
103
|
}
|
98
104
|
|
99
|
-
|
105
|
+
```
|
106
|
+
|
100
|
-
|
107
|
+
```
|
108
|
+
|
101
|
-
|
109
|
+
SiteEventLogic
|
102
110
|
|
103
111
|
package model;
|
104
112
|
|
@@ -120,9 +128,13 @@
|
|
120
128
|
|
121
129
|
}
|
122
130
|
|
123
|
-
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
124
|
-
|
135
|
+
```
|
136
|
+
|
125
|
-
|
137
|
+
servlet(contorol)
|
126
138
|
|
127
139
|
package servlet;
|
128
140
|
|
@@ -244,7 +256,7 @@
|
|
244
256
|
|
245
257
|
}
|
246
258
|
|
247
|
-
|
259
|
+
```
|
248
260
|
|
249
261
|
|
250
262
|
|
3
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Java servlet
|
1
|
+
Java servlet ブラウザごとに値を加算したい(簡易掲示板)
|
test
CHANGED
File without changes
|
2
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Java servlet ブラウザごとに値を
|
1
|
+
Java servlet ブラウザ ブラウザごとに値を加算したい(簡易掲示板)
|
test
CHANGED
File without changes
|
1
ソースコードの追加をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,221 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
#####jsp(view)
|
36
|
+
|
37
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
38
|
+
|
39
|
+
pageEncoding="UTF-8"%>
|
40
|
+
|
41
|
+
<!DOCTYPE html>
|
42
|
+
|
43
|
+
<html>
|
44
|
+
|
45
|
+
<head>
|
46
|
+
|
47
|
+
<meta charset="UTF-8">
|
48
|
+
|
49
|
+
<title>簡易掲示板</title>
|
50
|
+
|
51
|
+
</head>
|
52
|
+
|
53
|
+
<body>
|
54
|
+
|
55
|
+
<h1>なんかの投稿</h1>
|
56
|
+
|
57
|
+
<form action="./index12" method="Post">
|
58
|
+
|
59
|
+
<font size="5"><a href="./Contorol?action=yoine">いいね</a>:${yoine.yoineCount}人</font>
|
60
|
+
|
61
|
+
</body>
|
62
|
+
|
63
|
+
</html>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
#####java(model)
|
68
|
+
|
69
|
+
######SiteEvent
|
70
|
+
|
71
|
+
package model;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public class SiteEvent {
|
76
|
+
|
77
|
+
private int yoineCount = 0;
|
78
|
+
|
79
|
+
private int yokunaineCount = 0;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
public void setYoineCount(int yoineCount) {
|
84
|
+
|
85
|
+
this.yoineCount = yoineCount;
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public int getYoineCount() {
|
92
|
+
|
93
|
+
return yoineCount;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
######SiteEventLogic
|
102
|
+
|
103
|
+
package model;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
public class SiteEventLogic {
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public void yoinePlus(SiteEvent y) {
|
112
|
+
|
113
|
+
int count = y.getYoineCount();
|
114
|
+
|
115
|
+
count++;
|
116
|
+
|
117
|
+
y.setYoineCount(count);
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
######servlet(contorol)
|
126
|
+
|
127
|
+
package servlet;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
import java.io.IOException;
|
136
|
+
|
137
|
+
import javax.servlet.RequestDispatcher;
|
138
|
+
|
139
|
+
import javax.servlet.ServletContext;
|
140
|
+
|
141
|
+
import javax.servlet.ServletException;
|
142
|
+
|
143
|
+
import javax.servlet.annotation.WebServlet;
|
144
|
+
|
145
|
+
import javax.servlet.http.HttpServlet;
|
146
|
+
|
147
|
+
import javax.servlet.http.HttpServletRequest;
|
148
|
+
|
149
|
+
import javax.servlet.http.HttpServletResponse;
|
150
|
+
|
151
|
+
import model.SiteEvent;
|
152
|
+
|
153
|
+
import model.SiteEventLogic;
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
@WebServlet("/Contorol")
|
160
|
+
|
161
|
+
public class Contorol extends HttpServlet {
|
162
|
+
|
163
|
+
private static final long serialVersionUID = 1L;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
35
|
-
|
171
|
+
@Override
|
172
|
+
|
173
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
174
|
+
|
175
|
+
throws ServletException, IOException {
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
// 初回起動を判定するための処理
|
180
|
+
|
181
|
+
// アプリケーションスコープから値を取得
|
182
|
+
|
183
|
+
ServletContext sc = this.getServletContext();
|
184
|
+
|
185
|
+
SiteEvent y = (SiteEvent) sc.getAttribute("yoine");
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
// 初回起動判定の続き
|
190
|
+
|
191
|
+
// アプリケーションスコープに値がなければnewする
|
192
|
+
|
193
|
+
if(y == null) {
|
194
|
+
|
195
|
+
y = new SiteEvent();
|
196
|
+
|
197
|
+
sc.setAttribute("yoine", y);
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
// リクエストパラメーターの取得
|
204
|
+
|
205
|
+
request.setCharacterEncoding("UTF-8");
|
206
|
+
|
207
|
+
String yoine = request.getParameter("action");
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
// いいねボタン押されたら
|
212
|
+
|
213
|
+
if (yoine != null){
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
// SiteEventLogicでいいねを加算
|
218
|
+
|
219
|
+
SiteEventLogic yl = new SiteEventLogic();
|
220
|
+
|
221
|
+
yl.yoinePlus(y);
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
// いいねの数をアプリケーションスコープに保存
|
226
|
+
|
227
|
+
sc.setAttribute("yoine", y);
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
// フォワード
|
234
|
+
|
235
|
+
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/keijiban.jsp");
|
236
|
+
|
237
|
+
rd.forward(request, response);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
36
250
|
|
37
251
|
|
38
252
|
|