質問編集履歴
3
javaタグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
質問の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Struts2を使用してActionクラスから一覧データをjspに渡す方法
|
1
|
+
Struts2を使用してActionクラスからListを使って一覧データをjspに渡す方法
|
test
CHANGED
@@ -1,94 +1,90 @@
|
|
1
|
+
Javaを学習しはじめたばかりの初心者です。
|
2
|
+
|
1
|
-
Struts2の
|
3
|
+
現在Struts2の勉強をしております。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
|
6
|
-
|
7
|
-
|
5
|
+
前回の質問から進展があったので、再度質問させていただきます。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
|
12
|
-
|
7
|
+
|
8
|
+
|
13
|
-
|
9
|
+
やりたいこと
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
|
18
|
-
|
19
|
-
ログイン失敗通知画面
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
・DBAction.java
|
24
|
-
|
25
|
-
DB接続処理、
|
26
|
-
|
27
|
-
DBに登録されているデータと入力されているデータを照合し、一致するならoutput.jsp
|
28
|
-
|
29
|
-
|
11
|
+
DBに登録しあるデータの一覧を取得しjspに渡し
|
12
|
+
|
30
|
-
|
13
|
+
jspで表示する。
|
14
|
+
|
31
|
-
|
15
|
+
というものを作りたいです。
|
32
|
-
|
16
|
+
|
17
|
+
|
18
|
+
|
33
|
-
|
19
|
+
struts2ではsetter/getterを作成すればデータを保持してくれるという認識をしております。
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
20
|
+
|
38
|
-
|
39
|
-
|
21
|
+
Listを使用して、Actionクラス内で一覧を取得しjspに渡したいのですが、
|
40
|
-
|
22
|
+
|
41
|
-
|
23
|
+
Listを作成した際、どのように保持させ、どのようにjspで表示させればいいのでしょうか?
|
42
|
-
|
43
|
-
|
24
|
+
|
44
|
-
|
45
|
-
例)
|
46
|
-
|
47
|
-
id name pass
|
48
|
-
|
49
|
-
1 田中 tanaka
|
50
|
-
|
51
|
-
2 佐藤 satou
|
52
|
-
|
53
|
-
3 贅沢 zeitaku
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
id 1 pass tanaka でログインしても
|
58
|
-
|
59
|
-
|
25
|
+
みなさまの知恵をお貸し頂きたいです。
|
26
|
+
|
27
|
+
|
28
|
+
|
60
|
-
|
29
|
+
開発環境は
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
30
|
+
|
67
|
-
|
31
|
+
Struts2 2.5.10
|
68
|
-
|
32
|
+
|
69
|
-
tomcat8.5
|
33
|
+
tomcat 8.5
|
70
34
|
|
71
35
|
eclipse oxygen
|
72
36
|
|
73
|
-
struts2.5.10
|
74
|
-
|
75
37
|
MySQL8.0
|
76
38
|
|
39
|
+
を使用しております。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
index.jsp
|
44
|
+
|
77
|
-
|
45
|
+
```jsp
|
46
|
+
|
78
|
-
|
47
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
48
|
+
|
49
|
+
pageEncoding="UTF-8"%>
|
50
|
+
|
51
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
52
|
+
|
53
|
+
<html>
|
54
|
+
|
55
|
+
<head>
|
56
|
+
|
57
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
58
|
+
|
59
|
+
<title>Insert title here</title>
|
60
|
+
|
61
|
+
</head>
|
62
|
+
|
63
|
+
<body>
|
64
|
+
|
65
|
+
<form action="cop">
|
66
|
+
|
79
|
-
id
|
67
|
+
idを入力してください
|
80
|
-
|
68
|
+
|
81
|
-
name
|
69
|
+
<input type="text" name="id"><br>
|
82
|
-
|
70
|
+
|
83
|
-
pass
|
71
|
+
passを入力してください
|
72
|
+
|
84
|
-
|
73
|
+
<input type="text" name="pass"><br>
|
74
|
+
|
85
|
-
|
75
|
+
<input type="submit">
|
76
|
+
|
86
|
-
|
77
|
+
</form>
|
78
|
+
|
87
|
-
|
79
|
+
</body>
|
80
|
+
|
88
|
-
|
81
|
+
</html>
|
82
|
+
|
83
|
+
```
|
84
|
+
|
89
|
-
DBAction.j
|
85
|
+
DBAction.java
|
90
|
-
|
86
|
+
|
91
|
-
```
|
87
|
+
```java
|
92
88
|
|
93
89
|
package cop;
|
94
90
|
|
@@ -102,6 +98,10 @@
|
|
102
98
|
|
103
99
|
import java.sql.Statement;
|
104
100
|
|
101
|
+
import java.util.ArrayList;
|
102
|
+
|
103
|
+
import java.util.List;
|
104
|
+
|
105
105
|
|
106
106
|
|
107
107
|
public class DBAction {
|
@@ -120,11 +120,11 @@
|
|
120
120
|
|
121
121
|
public String execute() throws Exception{
|
122
122
|
|
123
|
-
String message="
|
123
|
+
String message="";
|
124
124
|
|
125
125
|
String user = "root";
|
126
126
|
|
127
|
-
String password = "ro
|
127
|
+
String password = "hirokida22";
|
128
128
|
|
129
129
|
String url="jdbc:mysql://localhost/worker?characterEncoding=UTF-8&serverTimezone=JST";
|
130
130
|
|
@@ -146,31 +146,33 @@
|
|
146
146
|
|
147
147
|
|
148
148
|
|
149
|
-
|
149
|
+
//全テーブルデータ取得
|
150
|
-
|
150
|
+
|
151
|
-
String sqlStr = "
|
151
|
+
String sqlStr = "SELECT * FROM shain";
|
152
152
|
|
153
153
|
ResultSet result=st.executeQuery(sqlStr);
|
154
154
|
|
155
|
+
|
156
|
+
|
155
|
-
/
|
157
|
+
//Listオブジェクトの生成
|
156
|
-
|
158
|
+
|
157
|
-
|
159
|
+
List<Syain> syainList = new ArrayList<Syain>();
|
158
|
-
|
159
|
-
|
160
|
+
|
160
|
-
|
161
|
-
|
161
|
+
|
162
|
+
|
163
|
+
|
162
164
|
|
163
165
|
while(result.next()) {
|
164
166
|
|
165
|
-
S
|
167
|
+
Syain syain =new Syain();
|
166
|
-
|
168
|
+
|
167
|
-
|
169
|
+
syain.setName(result.getString("name"));
|
170
|
+
|
168
|
-
|
171
|
+
syain.setId(result.getString("id"));
|
172
|
+
|
169
|
-
|
173
|
+
syain.setPass(result.getString("pass"));
|
170
|
-
|
174
|
+
|
171
|
-
s
|
175
|
+
syainList.add(syain);
|
172
|
-
|
173
|
-
getId();
|
174
176
|
|
175
177
|
|
176
178
|
|
@@ -178,7 +180,7 @@
|
|
178
180
|
|
179
181
|
|
180
182
|
|
181
|
-
return
|
183
|
+
return "success";
|
182
184
|
|
183
185
|
}
|
184
186
|
|
@@ -234,72 +236,110 @@
|
|
234
236
|
|
235
237
|
```
|
236
238
|
|
237
|
-
|
239
|
+
output.jsp
|
238
|
-
|
240
|
+
|
239
|
-
```
|
241
|
+
```jsp
|
242
|
+
|
240
|
-
|
243
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
244
|
+
|
245
|
+
pageEncoding="UTF-8"%>
|
246
|
+
|
241
|
-
<
|
247
|
+
<%@taglib prefix="s" uri="/struts-tags" %>
|
242
|
-
|
243
|
-
|
248
|
+
|
244
|
-
|
245
|
-
"-//
|
249
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
246
|
-
|
247
|
-
|
250
|
+
|
248
|
-
|
249
|
-
<
|
251
|
+
<html>
|
250
|
-
|
252
|
+
|
251
|
-
<
|
253
|
+
<head>
|
252
|
-
|
254
|
+
|
253
|
-
<
|
255
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
254
|
-
|
255
|
-
|
256
|
+
|
256
|
-
|
257
|
-
class = "cop.DBAction"
|
258
|
-
|
259
|
-
method = "execute">
|
260
|
-
|
261
|
-
<result name ="success">/output.jsp</result>
|
262
|
-
|
263
|
-
<
|
257
|
+
<title>Insert title here</title>
|
258
|
+
|
264
|
-
|
259
|
+
</head>
|
260
|
+
|
261
|
+
<body>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
ここに一覧表示をさせたい
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
</body>
|
272
|
+
|
265
|
-
</
|
273
|
+
</html>
|
266
|
-
|
267
|
-
</package>
|
268
|
-
|
269
|
-
</struts>
|
270
274
|
|
271
275
|
```
|
272
276
|
|
277
|
+
|
278
|
+
|
273
|
-
|
279
|
+
Syain.java
|
274
|
-
|
280
|
+
|
275
|
-
```
|
281
|
+
```java
|
282
|
+
|
276
|
-
|
283
|
+
package cop;
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
public class Syain {
|
288
|
+
|
289
|
+
|
290
|
+
|
277
|
-
|
291
|
+
private String name;
|
292
|
+
|
278
|
-
|
293
|
+
private String id;
|
294
|
+
|
295
|
+
private String pass;
|
296
|
+
|
279
|
-
|
297
|
+
public String getName() {
|
280
|
-
|
281
|
-
|
298
|
+
|
282
|
-
|
283
|
-
|
299
|
+
return name;
|
300
|
+
|
284
|
-
|
301
|
+
}
|
302
|
+
|
303
|
+
public void setName(String name) {
|
304
|
+
|
305
|
+
this.name = name;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
public String getId() {
|
310
|
+
|
311
|
+
return id;
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
public void setId(String id) {
|
316
|
+
|
317
|
+
this.id = id;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
public String getPass() {
|
322
|
+
|
285
|
-
|
323
|
+
return pass;
|
286
|
-
|
324
|
+
|
287
|
-
|
325
|
+
}
|
288
|
-
|
326
|
+
|
289
|
-
|
327
|
+
public void setPass(String pass) {
|
290
|
-
|
328
|
+
|
291
|
-
|
329
|
+
this.pass = pass;
|
292
|
-
|
293
|
-
|
330
|
+
|
294
|
-
|
295
|
-
|
331
|
+
}
|
296
|
-
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
297
|
-
|
337
|
+
}
|
298
|
-
|
299
|
-
|
338
|
+
|
339
|
+
|
300
340
|
|
301
341
|
```
|
302
342
|
|
303
343
|
|
304
344
|
|
305
|
-
|
345
|
+
どうかお助けください、よろしくお願い致します。
|
1
例の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -148,7 +148,7 @@
|
|
148
148
|
|
149
149
|
//入力されたpassの行を取得
|
150
150
|
|
151
|
-
String sqlStr = "select * from shain where id =
|
151
|
+
String sqlStr = "select * from shain where id ="+getId();
|
152
152
|
|
153
153
|
ResultSet result=st.executeQuery(sqlStr);
|
154
154
|
|