質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,7 +86,13 @@
|
|
86
86
|
|
87
87
|
```
|
88
88
|
|
89
|
+
```JAVA
|
90
|
+
|
91
|
+
|
92
|
+
|
89
|
-
|
93
|
+
【LoginAction.java】
|
94
|
+
|
95
|
+
|
90
96
|
|
91
97
|
package application;
|
92
98
|
|
@@ -216,7 +222,13 @@
|
|
216
222
|
|
217
223
|
|
218
224
|
|
225
|
+
```JSP
|
226
|
+
|
227
|
+
|
228
|
+
|
219
|
-
|
229
|
+
【home.jsp】
|
230
|
+
|
231
|
+
|
220
232
|
|
221
233
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
222
234
|
|
@@ -270,7 +282,13 @@
|
|
270
282
|
|
271
283
|
|
272
284
|
|
285
|
+
```JSP
|
286
|
+
|
287
|
+
|
288
|
+
|
273
|
-
|
289
|
+
【A.jsp】
|
290
|
+
|
291
|
+
|
274
292
|
|
275
293
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
276
294
|
|
@@ -316,7 +334,13 @@
|
|
316
334
|
|
317
335
|
|
318
336
|
|
337
|
+
```JSP
|
338
|
+
|
339
|
+
|
340
|
+
|
319
|
-
|
341
|
+
【B.jsp】
|
342
|
+
|
343
|
+
|
320
344
|
|
321
345
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
322
346
|
|
@@ -360,7 +384,13 @@
|
|
360
384
|
|
361
385
|
```
|
362
386
|
|
387
|
+
```Servlet
|
388
|
+
|
389
|
+
|
390
|
+
|
363
|
-
|
391
|
+
【SampleServlet.java】
|
392
|
+
|
393
|
+
|
364
394
|
|
365
395
|
package application;
|
366
396
|
|
@@ -442,18 +472,30 @@
|
|
442
472
|
|
443
473
|
|
444
474
|
|
475
|
+
【ログインフォーム】
|
476
|
+
|
445
477
|
![イメージ説明](4fae5c3dc23a2cabc66d7632f9c3ab4b.png)
|
446
478
|
|
447
479
|
|
448
480
|
|
481
|
+
【フレームでの2画面表示】
|
482
|
+
|
449
483
|
![イメージ説明](a283029432121def427bea2273922c5c.png)
|
450
484
|
|
451
485
|
|
452
486
|
|
487
|
+
【POST実行後】
|
488
|
+
|
453
489
|
![イメージ説明](d2e5a22e8dd6e3ef5a25dd3715857360.png)
|
454
490
|
|
455
491
|
|
456
492
|
|
493
|
+
【Eclipse構成】
|
494
|
+
|
495
|
+
![イメージ説明](002575292b03eb3050ce6549662907e1.png)
|
496
|
+
|
497
|
+
|
498
|
+
|
457
499
|
実現したいことの簡易コードを作成しました。
|
458
500
|
|
459
501
|
A.jspからコメントをPOSTして、B.jspのコメントを書き換えたいです。
|
1
再現簡易コードを作成しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,443 @@
|
|
33
33
|
考え方自体が間違っているでしょうか。
|
34
34
|
|
35
35
|
ご教示いただけますと幸いです。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```loin-in.jsp
|
42
|
+
|
43
|
+
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
44
|
+
|
45
|
+
<!DOCTYPE html>
|
46
|
+
|
47
|
+
<html>
|
48
|
+
|
49
|
+
<head>
|
50
|
+
|
51
|
+
<meta charset="UTF-8">
|
52
|
+
|
53
|
+
<title>ログインフォーム</title>
|
54
|
+
|
55
|
+
<style>
|
56
|
+
|
57
|
+
from backgroud-color: red;
|
58
|
+
|
59
|
+
</style>
|
60
|
+
|
61
|
+
</head>
|
62
|
+
|
63
|
+
<body>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
<div class="log-form" align="center">
|
68
|
+
|
69
|
+
<h5>Login to your account</h5>
|
70
|
+
|
71
|
+
<form action = "http://localhost:8080/fileConnector/LoginAction" method="post">
|
72
|
+
|
73
|
+
<p>user_id : <input type="text" name = "user_id" title="userid" placeholder="userid" /></p>
|
74
|
+
|
75
|
+
<p>user_comment : <input type="text" name = "user_comment" size="30" maxlength="20" placeholder="comment" /></p>
|
76
|
+
|
77
|
+
<p><input type="submit" value="Login"></p>
|
78
|
+
|
79
|
+
</form>
|
80
|
+
|
81
|
+
</div><!--end log form -->
|
82
|
+
|
83
|
+
</body>
|
84
|
+
|
85
|
+
</html>
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
```LoginAction.java
|
90
|
+
|
91
|
+
package application;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
import java.io.IOException;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
import javax.servlet.ServletException;
|
100
|
+
|
101
|
+
import javax.servlet.annotation.WebServlet;
|
102
|
+
|
103
|
+
import javax.servlet.http.HttpServlet;
|
104
|
+
|
105
|
+
import javax.servlet.http.HttpServletRequest;
|
106
|
+
|
107
|
+
import javax.servlet.http.HttpServletResponse;
|
108
|
+
|
109
|
+
import javax.servlet.http.HttpSession;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
import bean.User;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
/**
|
118
|
+
|
119
|
+
* Servlet implementation class TEST
|
120
|
+
|
121
|
+
*/
|
122
|
+
|
123
|
+
@WebServlet("/LoginAction")
|
124
|
+
|
125
|
+
public class LoginAction extends HttpServlet {
|
126
|
+
|
127
|
+
private static final long serialVersionUID = 1L;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
/**
|
132
|
+
|
133
|
+
* @see HttpServlet#HttpServlet()
|
134
|
+
|
135
|
+
*/
|
136
|
+
|
137
|
+
public LoginAction() {
|
138
|
+
|
139
|
+
super();
|
140
|
+
|
141
|
+
// TODO Auto-generated constructor stub
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/**
|
148
|
+
|
149
|
+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
150
|
+
|
151
|
+
*/
|
152
|
+
|
153
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
154
|
+
|
155
|
+
// TODO Auto-generated method stub
|
156
|
+
|
157
|
+
response.getWriter().append("Served at: ").append(request.getContextPath());
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
/**
|
164
|
+
|
165
|
+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
166
|
+
|
167
|
+
*/
|
168
|
+
|
169
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
// TODO Auto-generated method stub
|
174
|
+
|
175
|
+
request.setCharacterEncoding("UTF-8");
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
HttpSession session = request.getSession();
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
int user_id = Integer.parseInt(request.getParameter("user_id"));
|
184
|
+
|
185
|
+
String user_password = request.getParameter("user_password");
|
186
|
+
|
187
|
+
String user_comment = request.getParameter("user_comment");
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
User user = new User();
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
user.setUserId(user_id);
|
196
|
+
|
197
|
+
user.setPassword(user_password);
|
198
|
+
|
199
|
+
user.setComment(user_comment);
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
session.setAttribute("user", user);
|
204
|
+
|
205
|
+
request.getRequestDispatcher("home.jsp").forward(request, response);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```home.jsp
|
220
|
+
|
221
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
222
|
+
|
223
|
+
pageEncoding="UTF-8"%>
|
224
|
+
|
225
|
+
<!DOCTYPE html>
|
226
|
+
|
227
|
+
<html>
|
228
|
+
|
229
|
+
<head>
|
230
|
+
|
231
|
+
<meta charset="UTF-8">
|
232
|
+
|
233
|
+
<title>Insert title here</title>
|
234
|
+
|
235
|
+
</head>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
<frameset cols="500,*">
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<frame src="A.jsp" name="frame1" title="左フレーム">
|
244
|
+
|
245
|
+
<frame src="B.jsp" name="frame2" title="右フレーム">
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<noframes>
|
250
|
+
|
251
|
+
<body>
|
252
|
+
|
253
|
+
<p>フレームの代替内容</p>
|
254
|
+
|
255
|
+
</body>
|
256
|
+
|
257
|
+
</noframes>
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
</frameset>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
</body>
|
266
|
+
|
267
|
+
</html>
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
```A.jsp
|
274
|
+
|
275
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
276
|
+
|
277
|
+
pageEncoding="UTF-8"%>
|
278
|
+
|
279
|
+
<!DOCTYPE html>
|
280
|
+
|
281
|
+
<html>
|
282
|
+
|
283
|
+
<head>
|
284
|
+
|
285
|
+
<meta charset="UTF-8">
|
286
|
+
|
287
|
+
<title>Insert title here</title>
|
288
|
+
|
289
|
+
</head>
|
290
|
+
|
291
|
+
<body>
|
292
|
+
|
293
|
+
<h3>A.jsp</h3>
|
294
|
+
|
295
|
+
<br><br>
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
<form action="http://localhost:8080/fileConnector/SampleServlet" method="post">
|
300
|
+
|
301
|
+
<p>コメントの書き換え<br>
|
302
|
+
|
303
|
+
<input type="text" name = "user_comment" size="30" maxlength="20" placeholder=${user.comment}></p>
|
304
|
+
|
305
|
+
<p><input type="submit" value="update"></p>
|
306
|
+
|
307
|
+
</form>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
</body>
|
312
|
+
|
313
|
+
</html>
|
314
|
+
|
315
|
+
```
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
```B.jsp
|
320
|
+
|
321
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
322
|
+
|
323
|
+
pageEncoding="UTF-8"%>
|
324
|
+
|
325
|
+
<%@page import="bean.User"%>
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
<!DOCTYPE html>
|
330
|
+
|
331
|
+
<html>
|
332
|
+
|
333
|
+
<head>
|
334
|
+
|
335
|
+
<meta charset="UTF-8">
|
336
|
+
|
337
|
+
<title>Insert title here</title>
|
338
|
+
|
339
|
+
</head>
|
340
|
+
|
341
|
+
<body>
|
342
|
+
|
343
|
+
<h3>B.jsp</h3>
|
344
|
+
|
345
|
+
<br><br>
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
<% User user = (User) session.getAttribute("user");%>
|
350
|
+
|
351
|
+
<p>ユーザーID : <%=user.getUserId() %></p>
|
352
|
+
|
353
|
+
<p>コメント : <%=user.getComment() %></p>
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
</body>
|
358
|
+
|
359
|
+
</html>
|
360
|
+
|
361
|
+
```
|
362
|
+
|
363
|
+
```SampleServlet.java
|
364
|
+
|
365
|
+
package application;
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
import java.io.IOException;
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
import javax.servlet.RequestDispatcher;
|
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
|
+
import javax.servlet.http.HttpSession;
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
import bean.User;
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
/**
|
396
|
+
|
397
|
+
* Servlet implementation class SampleServlet
|
398
|
+
|
399
|
+
*/
|
400
|
+
|
401
|
+
@WebServlet("/SampleServlet")
|
402
|
+
|
403
|
+
public class SampleServlet extends HttpServlet {
|
404
|
+
|
405
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
request.setCharacterEncoding("UTF-8");
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
HttpSession session = request.getSession();
|
414
|
+
|
415
|
+
String user_comment = request.getParameter("user_comment");
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
User user = new User();
|
420
|
+
|
421
|
+
user.setComment(user_comment);
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
session.setAttribute("user", user);
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
RequestDispatcher dispatcher = request.getRequestDispatcher("B.jsp");
|
430
|
+
|
431
|
+
dispatcher.forward(request, response);
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
```
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
![イメージ説明](4fae5c3dc23a2cabc66d7632f9c3ab4b.png)
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
![イメージ説明](a283029432121def427bea2273922c5c.png)
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
![イメージ説明](d2e5a22e8dd6e3ef5a25dd3715857360.png)
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
実現したいことの簡易コードを作成しました。
|
458
|
+
|
459
|
+
A.jspからコメントをPOSTして、B.jspのコメントを書き換えたいです。
|
460
|
+
|
461
|
+
その際には、innerHTMLは使用せずにBeanを書き換えたものを再表示する方法で
|
462
|
+
|
463
|
+
B.jspを更新しなければなりません。
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
作成いただいたコードを実行すると、A.jspがB.jspに(そのようなコーディングであるためなのですが)なります。
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
A.jspのテキストが「こんにちは」のまま、B.jspのBean再読み込みはできるのでしょうか。
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
どうかお知恵をお貸しください。
|