質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
```
|
64
64
|
|
65
|
-
<h1>
|
65
|
+
<h1>更新</h1>
|
66
66
|
|
67
67
|
<form action="./Detail" method="post">
|
68
68
|
|
1
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -85,3 +85,395 @@
|
|
85
85
|
|
86
86
|
|
87
87
|
どこに問題があるでしょうか、詳しい方いらっしゃればご指摘願います。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
追記です。
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
どこの部分が必要かがわからないので関係ありそうな部分を全て記載します。
|
96
|
+
|
97
|
+
長文になって申し訳ありません・・・
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
public class listDao {
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
private static final String url = "jdbc:mysql://localhost:3306/test";
|
108
|
+
|
109
|
+
private static final String user = "root";
|
110
|
+
|
111
|
+
private static final String password = "";
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
private static Connection conn = null; // Connectionクラス
|
116
|
+
|
117
|
+
private static PreparedStatement pstmt = null; // Statementクラス
|
118
|
+
|
119
|
+
private static ResultSet rs = null; // ResultSetクラス
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
public ArrayList<Listinfo> findAll(String[] args) {
|
124
|
+
|
125
|
+
ArrayList<Listinfo> listInfos = new ArrayList<Listinfo>();
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
// SQL文
|
130
|
+
|
131
|
+
String sql = "SELECT * FROM e_state";
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
try {
|
136
|
+
|
137
|
+
Class.forName("com.mysql.jdbc.Driver");
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
conn = DriverManager.getConnection(url, user, password);
|
142
|
+
|
143
|
+
pstmt = conn.prepareStatement(sql);
|
144
|
+
|
145
|
+
rs = pstmt.executeQuery();
|
146
|
+
|
147
|
+
while (rs.next()) {
|
148
|
+
|
149
|
+
// 結果表からデータを取得
|
150
|
+
|
151
|
+
Listinfo list = new Listinfo();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
list.setEmployeeId(rs.getString("id"));
|
156
|
+
|
157
|
+
list.setName(rs.getString("name"));
|
158
|
+
|
159
|
+
list.setNameHiragana(rs.getString("name_hiragana"));
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
listInfos.add(list);
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
} catch (SQLException e) {
|
176
|
+
|
177
|
+
e.printStackTrace();
|
178
|
+
|
179
|
+
} catch (ClassNotFoundException e) {
|
180
|
+
|
181
|
+
} finally {
|
182
|
+
|
183
|
+
if (rs != null) {
|
184
|
+
|
185
|
+
try {
|
186
|
+
|
187
|
+
rs.close();
|
188
|
+
|
189
|
+
} catch (SQLException e) {
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
rs = null;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
if (pstmt != null) {
|
198
|
+
|
199
|
+
try {
|
200
|
+
|
201
|
+
pstmt.close();
|
202
|
+
|
203
|
+
} catch (SQLException e) {
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
pstmt = null;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
if (conn != null) {
|
212
|
+
|
213
|
+
try {
|
214
|
+
|
215
|
+
conn.close();
|
216
|
+
|
217
|
+
} catch (SQLException e) {
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
conn = null;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
return listInfos;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
package dto;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
public class Listinfo {
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
private String Id;
|
246
|
+
|
247
|
+
private String name;
|
248
|
+
|
249
|
+
private String nameHiragana;
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
public String getId() { return Id; }
|
256
|
+
|
257
|
+
public String getName() { return name; }
|
258
|
+
|
259
|
+
public String getNameHiragana() { return nameHiragana; }
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
public void setId(String Id) { this.Id = Id; }
|
266
|
+
|
267
|
+
public void setName(String name) { this.name = name; }
|
268
|
+
|
269
|
+
public void setNameHiragana(String nameHiragana) { this.nameHiragana = nameHiragana; }
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
```
|
278
|
+
|
279
|
+
package servlet;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
import java.io.IOException;
|
284
|
+
|
285
|
+
import java.util.ArrayList;
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
import javax.servlet.ServletException;
|
290
|
+
|
291
|
+
import javax.servlet.annotation.WebServlet;
|
292
|
+
|
293
|
+
import javax.servlet.http.HttpServlet;
|
294
|
+
|
295
|
+
import javax.servlet.http.HttpServletRequest;
|
296
|
+
|
297
|
+
import javax.servlet.http.HttpServletResponse;
|
298
|
+
|
299
|
+
import javax.servlet.http.HttpSession;
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
import Dao.listDao;
|
304
|
+
|
305
|
+
import dto.Logininfo;
|
306
|
+
|
307
|
+
import dto.Listinfo;
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
@WebServlet("/List")
|
312
|
+
|
313
|
+
public class List extends HttpServlet {
|
314
|
+
|
315
|
+
private static final long serialVersionUID = 1L;
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
320
|
+
|
321
|
+
// TODO Auto-generated method stub
|
322
|
+
|
323
|
+
//session切れでログイン画面に戻す
|
324
|
+
|
325
|
+
HttpSession session = request.getSession();
|
326
|
+
|
327
|
+
Logininfo login = (Logininfo)session.getAttribute("user");
|
328
|
+
|
329
|
+
if(login == null) {
|
330
|
+
|
331
|
+
response.sendRedirect("./Login");
|
332
|
+
|
333
|
+
return;
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
listDao daoArray = new listDao();
|
340
|
+
|
341
|
+
ArrayList<Listinfo> listInfo = daoArray.findAll(null);
|
342
|
+
|
343
|
+
request.setAttribute("list", listInfo);
|
344
|
+
|
345
|
+
request.getRequestDispatcher("/WEB-INF/jsp/list.jsp").forward(request, response);
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
//list.jspへ
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
public void doPost(HttpServletRequest request, HttpServletResponse response) {
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
```
|
362
|
+
|
363
|
+
```
|
364
|
+
|
365
|
+
package servlet;
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
import java.io.IOException;
|
370
|
+
|
371
|
+
import java.sql.SQLException;
|
372
|
+
|
373
|
+
import java.util.ArrayList;
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
import javax.servlet.ServletException;
|
378
|
+
|
379
|
+
import javax.servlet.annotation.WebServlet;
|
380
|
+
|
381
|
+
import javax.servlet.http.HttpServlet;
|
382
|
+
|
383
|
+
import javax.servlet.http.HttpServletRequest;
|
384
|
+
|
385
|
+
import javax.servlet.http.HttpServletResponse;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
import Dao.listDao;
|
390
|
+
|
391
|
+
import dto.Listinfo;
|
392
|
+
|
393
|
+
import dto.Listinfo2;
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
/**
|
398
|
+
|
399
|
+
* Servlet implementation class Detail
|
400
|
+
|
401
|
+
*/
|
402
|
+
|
403
|
+
@WebServlet("/Detail")
|
404
|
+
|
405
|
+
public class Detail extends HttpServlet {
|
406
|
+
|
407
|
+
private static final long serialVersionUID = 1L;
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
protected void doGet(HttpServletRequest request,
|
412
|
+
|
413
|
+
HttpServletResponse response) throws ServletException, IOException {
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
/**
|
420
|
+
|
421
|
+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
422
|
+
|
423
|
+
*/
|
424
|
+
|
425
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
426
|
+
|
427
|
+
// HttpSession session = request.getSession();
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
request.setCharacterEncoding("UTF-8");
|
432
|
+
|
433
|
+
String Id = request.getParameter("Id");
|
434
|
+
|
435
|
+
String name = request.getParameter("name");
|
436
|
+
|
437
|
+
String name_hiragana = request.getParameter("nameHiragana");
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
listDao dao = new listDao(); //Daoクラス生成
|
442
|
+
|
443
|
+
try {
|
444
|
+
|
445
|
+
dao.InsertInformation(Id, name, name_hiragana);
|
446
|
+
|
447
|
+
} catch (ClassNotFoundException e) {
|
448
|
+
|
449
|
+
// TODO 自動生成された catch ブロック
|
450
|
+
|
451
|
+
e.printStackTrace();
|
452
|
+
|
453
|
+
} catch (SQLException e) {
|
454
|
+
|
455
|
+
// TODO 自動生成された catch ブロック
|
456
|
+
|
457
|
+
e.printStackTrace();
|
458
|
+
|
459
|
+
} //挿入処理}
|
460
|
+
|
461
|
+
// session.setAttribute("Infomation", dao);
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
response.sendRedirect("./List");
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
```
|
472
|
+
|
473
|
+
Updateのsql文処理の部分はまだ用意してないです。
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
以上で足りるでしょうか?
|
478
|
+
|
479
|
+
宜しくお願い致します。
|