質問編集履歴

1

修正

2018/12/02 03:12

投稿

samurai_se
samurai_se

スコア15

test CHANGED
File without changes
test CHANGED
@@ -24,11 +24,173 @@
24
24
 
25
25
 
26
26
 
27
+
28
+
29
+
30
+
27
- ■入力画面JSP
31
+ ■入力した値をrequestで受け取り、次の画面へ渡すためのクラス
28
-
32
+
29
- ```JSP
33
+ ```Java
34
+
30
-
35
+ package action;
36
+
37
+
38
+
39
+ import javax.servlet.http.HttpServletRequest;
40
+
41
+ import javax.servlet.http.HttpServletResponse;
42
+
43
+
44
+
45
+ import tool.Action;
46
+
47
+ import tool.Verify;
48
+
49
+ import util.StringQuery;
50
+
51
+ import util.StringUtil;
52
+
53
+
54
+
55
+
56
+
57
+ public class RegistCheckAction extends Action{
58
+
59
+
60
+
61
+ /**
62
+
63
+ *
64
+
65
+ * 検証用クラスのインスタンス化
66
+
67
+ *
68
+
69
+ */
70
+
71
+ Verify vr = new Verify();
72
+
73
+
74
+
75
+ public String execute(
76
+
77
+ HttpServletRequest request, HttpServletResponse response) throws Exception{
78
+
79
+
80
+
81
+ response.setContentType("text/html; charset=UTF-8");
82
+
83
+ request.setCharacterEncoding("UTF-8");
84
+
85
+
86
+
87
+ String booktitle = request.getParameter(StringQuery.BOOKTITLE);
88
+
89
+ String author = request.getParameter(StringQuery.AUTHOR);
90
+
91
+ String publisher = request.getParameter(StringQuery.PUBLISHER);
92
+
93
+ String publishday = request.getParameter(StringQuery.PUBLISHDAY);
94
+
95
+ String category = request.getParameter(StringQuery.CATEGORY);
96
+
97
+
98
+
99
+ int btcheck = vr.booktitleVerify(booktitle);
100
+
101
+ int aucheck = vr.authorVerify(author);
102
+
103
+ int yearcheck = vr.publishedYearVerify(publishday);
104
+
105
+
106
+
107
+ if(btcheck==StringUtil.MOJHI_OK && aucheck==StringUtil.MOJHI_OK
108
+
109
+ && yearcheck==StringUtil.MOJHI_OK){
110
+
111
+
112
+
113
+ setBookInformation(booktitle,author,publisher,publishday,category,request);
114
+
115
+
116
+
117
+ return StringUtil.VIEW_FOLDER + StringUtil.SLASH + StringUtil.PAGE_REGIST_CHECK
118
+
119
+ + StringUtil.DOT + StringUtil.JSP_EXTENSION;
120
+
121
+
122
+
123
+ }else{
124
+
125
+
126
+
127
+ setBookInformation(booktitle,author,publisher,publishday,category,request);
128
+
129
+
130
+
131
+ request.setAttribute(StringQuery.BOOKTITLE_CK, btcheck);
132
+
133
+ request.setAttribute(StringQuery.AUTHOR_CK, aucheck);
134
+
135
+ request.setAttribute(StringQuery.PUBLISHDAY_CK, yearcheck);
136
+
137
+
138
+
139
+ return StringUtil.VIEW_FOLDER + StringUtil.SLASH + StringUtil.PAGE_REGIST
140
+
141
+ + StringUtil.DOT + StringUtil.JSP_EXTENSION;
142
+
143
+
144
+
145
+ }
146
+
147
+
148
+
149
+ }
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+ private void setBookInformation(String booktitle, String author, String publisher, String publishday
160
+
161
+ ,String category,HttpServletRequest request) {
162
+
163
+
164
+
165
+ request.setAttribute(StringQuery.BOOKTITLE, booktitle);
166
+
167
+ request.setAttribute(StringQuery.AUTHOR, author);
168
+
169
+ request.setAttribute(StringQuery.PUBLISHER, publisher);
170
+
171
+ request.setAttribute(StringQuery.PUBLISHDAY, publishday);
172
+
173
+ request.setAttribute(StringQuery.CATEGORY, category);
174
+
175
+
176
+
177
+ }
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+ }
186
+
187
+ ```
188
+
189
+
190
+
191
+ ■入力確認画面
192
+
31
- <%@ page language="java" contentType="text/html; charset=UTF-8"
193
+ ```JSP<%@ page language="java" contentType="text/html; charset=UTF-8"
32
194
 
33
195
  pageEncoding="UTF-8"%>
34
196
 
@@ -36,11 +198,11 @@
36
198
 
37
199
  <%@page import="util.StringQuery"%>
38
200
 
39
-
201
+ <%@page import="java.text.SimpleDateFormat"%>
202
+
40
-
203
+ <%@page import="java.util.Calendar"%>
204
+
41
-
205
+ <% Calendar cal = Calendar.getInstance();%>
42
-
43
-
44
206
 
45
207
 
46
208
 
@@ -58,7 +220,7 @@
58
220
 
59
221
  <script type="text/javascript" src="<%=StringUtil.MAINJS%>"></script>
60
222
 
61
- <meta charset="<%=StringUtil.SET_ENCODING%>" />
223
+ <meta charset="<%=StringUtil.SET_ENCODING %>" />
62
224
 
63
225
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
64
226
 
@@ -78,7 +240,9 @@
78
240
 
79
241
 
80
242
 
243
+ <form
244
+
81
- <form action="<%=StringUtil.REGISTCHECK + StringUtil.CONTROLLER%>"
245
+ action="<%=StringUtil.REGISTCOMPLETE + StringUtil.CONTROLLER %>"
82
246
 
83
247
  method="post">
84
248
 
@@ -86,186 +250,148 @@
86
250
 
87
251
  <div>
88
252
 
89
- <label for="form-userid">BoolTitle</label> <input type="text"
90
-
91
- name="booktitle" id="form-userid" placeholder="BookTitle"
92
-
93
- value="<%if (request.getAttribute(StringQuery.BOOKTITLE) != null)
94
-
95
- out.println(request.getAttribute(StringQuery.BOOKTITLE));%>" />
253
+ BookTitle:<%=request.getAttribute(StringQuery.BOOKTITLE)%></div>
254
+
96
-
255
+ <div>
256
+
97
- <p class="note">Please enter BookTitle.</p>
257
+ Author:<%=request.getAttribute(StringQuery.AUTHOR)%></div>
258
+
259
+ <div>
260
+
261
+ Publisher:<%=request.getAttribute(StringQuery.PUBLISHER)%></div>
262
+
263
+ <div>
264
+
265
+ Publishday:<%=request.getAttribute(StringQuery.PUBLISHDAY)%></div>
266
+
267
+ <div>
268
+
269
+ Category:
270
+
271
+ <%
272
+
273
+ String checkchar = (String)request.getAttribute(StringQuery.CATEGORY);
274
+
275
+ out.println(dispCategory(checkchar));
276
+
277
+ %>
278
+
279
+
280
+
281
+ <%! String dispCategory(String checkchar){
282
+
283
+
284
+
285
+ if(checkchar=="7"){
286
+
287
+
288
+
289
+ return "";
290
+
291
+
292
+
293
+ }else if(checkchar=="1"){
294
+
295
+
296
+
297
+ return "漫画";
298
+
299
+
300
+
301
+ }else if(checkchar=="2"){
302
+
303
+
304
+
305
+ return "文庫";
306
+
307
+
308
+
309
+ }else if (checkchar=="3"){
310
+
311
+
312
+
313
+ return "大型本";
314
+
315
+
316
+
317
+ }else if (checkchar=="4"){
318
+
319
+
320
+
321
+ return "雑誌";
322
+
323
+
324
+
325
+ }else if (checkchar=="5" || checkchar.equals("5")){
326
+
327
+
328
+
329
+ return "参考書";
330
+
331
+
332
+
333
+ }else{
334
+
335
+
336
+
337
+ return "新書";
338
+
339
+
340
+
341
+ }
342
+
343
+
344
+
345
+ }%>
346
+
347
+
98
348
 
99
349
  </div>
100
350
 
101
- <div>
351
+
102
-
103
- <%
352
+
104
-
105
- if (request.getAttribute(StringQuery.BOOKTITLE_CK) != null) {
353
+ <input type="hidden" name="booktitle"
106
-
107
- if ((int) request.getAttribute(StringQuery.BOOKTITLE_CK) == StringUtil.BOOKTITLE_NULL) {
354
+
108
-
109
-
110
-
111
- out.println("<p id=" + "error_message" + ">" + StringUtil.BOOKTITLE_IS_NULL + "</p>");
112
-
113
-
114
-
115
- } else if ((int) request.getAttribute(StringQuery.BOOKTITLE_CK) == StringUtil.BOOKTITLE_LENGTH) {
355
+ value="<%=request.getAttribute(StringQuery.BOOKTITLE)%>" /> <input
356
+
116
-
357
+ type="hidden" name="author"
358
+
117
-
359
+ value="<%=request.getAttribute(StringQuery.AUTHOR)%>" /> <input
360
+
118
-
361
+ type="hidden" name="publisher"
362
+
363
+ value="<%=request.getAttribute(StringQuery.PUBLISHER)%>" /> <input
364
+
365
+ type="hidden" name="publishday"
366
+
367
+ value="<%=request.getAttribute(StringQuery.PUBLISHDAY)%>" /> <input
368
+
369
+ type="hidden" name="runame"
370
+
371
+ value="<%=session.getAttribute(StringQuery.USERNAME) %>" /> <input
372
+
373
+ type="hidden" name="registday"
374
+
375
+ value="<%=cal.get(Calendar.YEAR)
376
+
119
- out.println("<p id=" + "error_message" + ">" + StringUtil.BOOKTITLE_OVER_LENGTH + "</p>");
377
+ + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH)%>" />
120
-
121
-
122
-
123
- }
378
+
124
-
125
- }
126
-
127
- %>
128
-
129
- </div>
379
+ <input type="hidden" name="category"
380
+
130
-
381
+ value="<%=request.getAttribute(StringQuery.CATEGORY)%>" />
382
+
383
+
384
+
385
+
386
+
387
+
388
+
131
-
389
+ <input type="submit" name="submit" value="Regist" />
132
390
 
133
391
 
134
392
 
135
393
 
136
394
 
137
- <div>
138
-
139
- <label for="form-userid">Author</label> <input type="text"
140
-
141
- name="author" id="form-userid" placeholder="author"
142
-
143
- value="<%if (request.getAttribute(StringQuery.AUTHOR) != null)
144
-
145
- out.println(request.getAttribute(StringQuery.AUTHOR));%>" />
146
-
147
- <p class="note">Please enter author.</p>
148
-
149
- </div>
150
-
151
- <div>
152
-
153
- <%
154
-
155
- if (request.getAttribute(StringQuery.AUTHOR_CK) != null) {
156
-
157
- if ((int) request.getAttribute(StringQuery.AUTHOR_CK) == StringUtil.AUTHOR_NULL) {
158
-
159
-
160
-
161
- out.println("<p id=" + "error_message" + ">" + StringUtil.AUTHOR_IS_NULL + "</p>");
162
-
163
-
164
-
165
- }
166
-
167
- }
168
-
169
- %>
170
-
171
- </div>
172
-
173
-
174
-
175
- <div>
176
-
177
- <label for="form-userid">Publisher</label> <input type="text"
178
-
179
- name="publisher" id="form-userid" placeholder="publisher"
180
-
181
- value="<%if (request.getAttribute(StringQuery.PUBLISHER) != null)
182
-
183
- out.println(request.getAttribute(StringQuery.PUBLISHER));%>" />
184
-
185
- <p class="note">Please enter Publisher.</p>
186
-
187
- </div>
188
-
189
-
190
-
191
-
192
-
193
- <div>
194
-
195
- <label for="form-userid">PublishDay</label> <input type="text"
196
-
197
- name="publishday" id="form-userid" placeholder="published Year"
198
-
199
- value="<%if (request.getAttribute(StringQuery.PUBLISHDAY) != null)
200
-
201
- out.println(request.getAttribute(StringQuery.PUBLISHDAY));%>" />
202
-
203
- <p class="note">Please enter published Year.</p>
204
-
205
- </div>
206
-
207
- <div>
208
-
209
- <%
210
-
211
- if (request.getAttribute(StringQuery.PUBLISHDAY_CK) != null) {
212
-
213
- if ((int) request.getAttribute(StringQuery.PUBLISHDAY_CK) == StringUtil.YEAR_OVER) {
214
-
215
-
216
-
217
- out.println("<p id=" + "error_message" + ">" + StringUtil.PUBLISHYEAR_FUTURE + "</p>");
218
-
219
-
220
-
221
- } else if ((int) request.getAttribute(StringQuery.PUBLISHDAY_CK) == StringUtil.NOT_NUMBER) {
222
-
223
-
224
-
225
- out.println("<p id=" + "error_message" + ">" + StringUtil.PUBLISHYEAR_INVALIDATE + "</p>");
226
-
227
-
228
-
229
- }
230
-
231
- }
232
-
233
- %>
234
-
235
- </div>
236
-
237
-
238
-
239
- <div>
240
-
241
- <span>Category:</span><select name=<%=StringQuery.CATEGORY %>>
242
-
243
- <option value=”7” selected></option>
244
-
245
- <option value=”1”>漫画</option>
246
-
247
- <option value=”2”>文庫</option>
248
-
249
- <option value=”3”>大型本</option>
250
-
251
- <option value=”4”>雑誌</option>
252
-
253
- <option value=”5”>参考書</option>
254
-
255
- <option value=”6”>新書</option>
256
-
257
- </select>
258
-
259
- </div>
260
-
261
-
262
-
263
- <br/>
264
-
265
-
266
-
267
- <input type="submit" name="submit" value="Regist" />
268
-
269
395
 
270
396
 
271
397
  </form>
@@ -284,394 +410,10 @@
284
410
 
285
411
  </html>
286
412
 
287
-
288
-
289
413
  ```
290
414
 
291
415
 
292
416
 
293
-
294
-
295
- ■入力した値をrequestで受け取り、次の画面へ渡すためのクラス
296
-
297
- ```Java
298
-
299
- package action;
300
-
301
-
302
-
303
- import javax.servlet.http.HttpServletRequest;
304
-
305
- import javax.servlet.http.HttpServletResponse;
306
-
307
-
308
-
309
- import tool.Action;
310
-
311
- import tool.Verify;
312
-
313
- import util.StringQuery;
314
-
315
- import util.StringUtil;
316
-
317
-
318
-
319
-
320
-
321
- public class RegistCheckAction extends Action{
322
-
323
-
324
-
325
- /**
326
-
327
- *
328
-
329
- * 検証用クラスのインスタンス化
330
-
331
- *
332
-
333
- */
334
-
335
- Verify vr = new Verify();
336
-
337
-
338
-
339
- public String execute(
340
-
341
- HttpServletRequest request, HttpServletResponse response) throws Exception{
342
-
343
-
344
-
345
- response.setContentType("text/html; charset=UTF-8");
346
-
347
- request.setCharacterEncoding("UTF-8");
348
-
349
-
350
-
351
- String booktitle = request.getParameter(StringQuery.BOOKTITLE);
352
-
353
- String author = request.getParameter(StringQuery.AUTHOR);
354
-
355
- String publisher = request.getParameter(StringQuery.PUBLISHER);
356
-
357
- String publishday = request.getParameter(StringQuery.PUBLISHDAY);
358
-
359
- String category = request.getParameter(StringQuery.CATEGORY);
360
-
361
-
362
-
363
- int btcheck = vr.booktitleVerify(booktitle);
364
-
365
- int aucheck = vr.authorVerify(author);
366
-
367
- int yearcheck = vr.publishedYearVerify(publishday);
368
-
369
-
370
-
371
- if(btcheck==StringUtil.MOJHI_OK && aucheck==StringUtil.MOJHI_OK
372
-
373
- && yearcheck==StringUtil.MOJHI_OK){
374
-
375
-
376
-
377
- setBookInformation(booktitle,author,publisher,publishday,category,request);
378
-
379
-
380
-
381
- return StringUtil.VIEW_FOLDER + StringUtil.SLASH + StringUtil.PAGE_REGIST_CHECK
382
-
383
- + StringUtil.DOT + StringUtil.JSP_EXTENSION;
384
-
385
-
386
-
387
- }else{
388
-
389
-
390
-
391
- setBookInformation(booktitle,author,publisher,publishday,category,request);
392
-
393
-
394
-
395
- request.setAttribute(StringQuery.BOOKTITLE_CK, btcheck);
396
-
397
- request.setAttribute(StringQuery.AUTHOR_CK, aucheck);
398
-
399
- request.setAttribute(StringQuery.PUBLISHDAY_CK, yearcheck);
400
-
401
-
402
-
403
- return StringUtil.VIEW_FOLDER + StringUtil.SLASH + StringUtil.PAGE_REGIST
404
-
405
- + StringUtil.DOT + StringUtil.JSP_EXTENSION;
406
-
407
-
408
-
409
- }
410
-
411
-
412
-
413
- }
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
- private void setBookInformation(String booktitle, String author, String publisher, String publishday
424
-
425
- ,String category,HttpServletRequest request) {
426
-
427
-
428
-
429
- request.setAttribute(StringQuery.BOOKTITLE, booktitle);
430
-
431
- request.setAttribute(StringQuery.AUTHOR, author);
432
-
433
- request.setAttribute(StringQuery.PUBLISHER, publisher);
434
-
435
- request.setAttribute(StringQuery.PUBLISHDAY, publishday);
436
-
437
- request.setAttribute(StringQuery.CATEGORY, category);
417
+ ### request.getAttribute(StringQuery.CATEGORY)の中身
438
-
439
-
440
-
441
- }
418
+
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
- }
450
-
451
- ```
452
-
453
-
454
-
455
- ■入力確認画面
456
-
457
- ```JSP<%@ page language="java" contentType="text/html; charset=UTF-8"
458
-
459
- pageEncoding="UTF-8"%>
460
-
461
- <%@page import="util.StringUtil"%>
462
-
463
- <%@page import="util.StringQuery"%>
464
-
465
- <%@page import="java.text.SimpleDateFormat"%>
466
-
467
- <%@page import="java.util.Calendar"%>
468
-
469
- <% Calendar cal = Calendar.getInstance();%>
419
+ ![イメージ説明](d43f438d514fcaebaa38748a7e4d9cdb.jpeg)
470
-
471
-
472
-
473
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
474
-
475
- <head>
476
-
477
- <title>Top</title>
478
-
479
-
480
-
481
- <link href='<%=StringUtil.CONTEXTPATH + StringUtil.INPUTCSS%>'
482
-
483
- rel='stylesheet' type='text/css' />
484
-
485
- <script type="text/javascript" src="<%=StringUtil.MAINJS%>"></script>
486
-
487
- <meta charset="<%=StringUtil.SET_ENCODING %>" />
488
-
489
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
490
-
491
-
492
-
493
- </head>
494
-
495
-
496
-
497
- <body>
498
-
499
- <div class="container">
500
-
501
- <div id="login-form">
502
-
503
- <div id="box">
504
-
505
-
506
-
507
- <form
508
-
509
- action="<%=StringUtil.REGISTCOMPLETE + StringUtil.CONTROLLER %>"
510
-
511
- method="post">
512
-
513
-
514
-
515
- <div>
516
-
517
- BookTitle:<%=request.getAttribute(StringQuery.BOOKTITLE)%></div>
518
-
519
- <div>
520
-
521
- Author:<%=request.getAttribute(StringQuery.AUTHOR)%></div>
522
-
523
- <div>
524
-
525
- Publisher:<%=request.getAttribute(StringQuery.PUBLISHER)%></div>
526
-
527
- <div>
528
-
529
- Publishday:<%=request.getAttribute(StringQuery.PUBLISHDAY)%></div>
530
-
531
- <div>
532
-
533
- Category:
534
-
535
- <%
536
-
537
- String checkchar = (String)request.getAttribute(StringQuery.CATEGORY);
538
-
539
- out.println(dispCategory(checkchar));
540
-
541
- %>
542
-
543
-
544
-
545
- <%! String dispCategory(String checkchar){
546
-
547
-
548
-
549
- if(checkchar=="7"){
550
-
551
-
552
-
553
- return "";
554
-
555
-
556
-
557
- }else if(checkchar=="1"){
558
-
559
-
560
-
561
- return "漫画";
562
-
563
-
564
-
565
- }else if(checkchar=="2"){
566
-
567
-
568
-
569
- return "文庫";
570
-
571
-
572
-
573
- }else if (checkchar=="3"){
574
-
575
-
576
-
577
- return "大型本";
578
-
579
-
580
-
581
- }else if (checkchar=="4"){
582
-
583
-
584
-
585
- return "雑誌";
586
-
587
-
588
-
589
- }else if (checkchar=="5" || checkchar.equals("5")){
590
-
591
-
592
-
593
- return "参考書";
594
-
595
-
596
-
597
- }else{
598
-
599
-
600
-
601
- return "新書";
602
-
603
-
604
-
605
- }
606
-
607
-
608
-
609
- }%>
610
-
611
-
612
-
613
- </div>
614
-
615
-
616
-
617
- <input type="hidden" name="booktitle"
618
-
619
- value="<%=request.getAttribute(StringQuery.BOOKTITLE)%>" /> <input
620
-
621
- type="hidden" name="author"
622
-
623
- value="<%=request.getAttribute(StringQuery.AUTHOR)%>" /> <input
624
-
625
- type="hidden" name="publisher"
626
-
627
- value="<%=request.getAttribute(StringQuery.PUBLISHER)%>" /> <input
628
-
629
- type="hidden" name="publishday"
630
-
631
- value="<%=request.getAttribute(StringQuery.PUBLISHDAY)%>" /> <input
632
-
633
- type="hidden" name="runame"
634
-
635
- value="<%=session.getAttribute(StringQuery.USERNAME) %>" /> <input
636
-
637
- type="hidden" name="registday"
638
-
639
- value="<%=cal.get(Calendar.YEAR)
640
-
641
- + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH)%>" />
642
-
643
- <input type="hidden" name="category"
644
-
645
- value="<%=request.getAttribute(StringQuery.CATEGORY)%>" />
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
- <input type="submit" name="submit" value="Regist" />
654
-
655
-
656
-
657
-
658
-
659
-
660
-
661
- </form>
662
-
663
-
664
-
665
- </div>
666
-
667
- </div>
668
-
669
- </div>
670
-
671
-
672
-
673
- </body>
674
-
675
- </html>
676
-
677
- ```