質問するログイン新規登録

質問編集履歴

4

誤植

2021/12/21 03:58

投稿

Mequitazine
Mequitazine

スコア8

title CHANGED
File without changes
body CHANGED
@@ -282,8 +282,4 @@
282
282
  </center>
283
283
  </body>
284
284
  </html>
285
- ```
285
+ ```
286
-
287
- 12/21 現在
288
- ビルドし直したところエラーが変化しました。
289
- ![イメージ説明](38acecea15583f5331a8e8098c261cb4.png)

3

エラーコード画像の追加

2021/12/21 03:58

投稿

Mequitazine
Mequitazine

スコア8

title CHANGED
File without changes
body CHANGED
@@ -282,4 +282,8 @@
282
282
  </center>
283
283
  </body>
284
284
  </html>
285
- ```
285
+ ```
286
+
287
+ 12/21 現在
288
+ ビルドし直したところエラーが変化しました。
289
+ ![イメージ説明](38acecea15583f5331a8e8098c261cb4.png)

2

htmlのソースコードを追加

2021/12/21 03:43

投稿

Mequitazine
Mequitazine

スコア8

title CHANGED
File without changes
body CHANGED
@@ -253,4 +253,33 @@
253
253
  }
254
254
  }
255
255
 
256
+ ```
257
+
258
+ ```html
259
+ <!DOCTYPE html>
260
+ <html>
261
+ <head>
262
+ <meta charset="UTF-8">
263
+ <title>口座操作画面</title>
264
+ </head>
265
+
266
+ <body>
267
+ <center>
268
+ <div id="top-main">
269
+ <h1>いらっしゃいませ</h1>
270
+ <h2>操作をお選び下さい</h2>
271
+ </div>
272
+ <!-- 選択 -->
273
+ <nav class="menu">
274
+ <ul>
275
+ <li class="menu_item"><a href="open">口座開設</a></li>
276
+ <li class="menu_item"><a href="close">口座解約</a></li>
277
+ <li class="menu_item"><a href="deposit">お預入れ</a></li>
278
+ <li class="menu_item"><a href="withdraw">お引出し</a></li>
279
+ <li class="menu_item"><a href="balance">残高照会</a></li>
280
+ </ul>
281
+ </nav>
282
+ </center>
283
+ </body>
284
+ </html>
256
285
  ```

1

今回使用しているソースコードを追加しました。

2021/12/20 14:52

投稿

Mequitazine
Mequitazine

スコア8

title CHANGED
File without changes
body CHANGED
@@ -3,4 +3,254 @@
3
3
 
4
4
  サーブレットのソースファイルをコンパイルした際には、エラーは発生しておらずクラスファイルの作成もできています。
5
5
 
6
- コードなどが必要でしたら、ご指摘下さい。
6
+ コードなどが必要でしたら、ご指摘下さい。
7
+
8
+ ```java
9
+ public class Account{
10
+ private String name; //口座名
11
+ private int balance; //口座の残高
12
+
13
+ public Account(String myName){ //口座名
14
+ name = myName;
15
+ balance = 0;
16
+ }
17
+
18
+ public int deposit(int amount){ //預金額
19
+ if(amount <= 0)
20
+ return -3;
21
+ else
22
+ balance += amount;
23
+ return 0;
24
+ }
25
+
26
+ public int withdraw(int amount){ //出金額
27
+ if(amount <= 0)
28
+ return -3;
29
+ else if(amount > balance)
30
+ return -1;
31
+ else
32
+ balance -= amount;
33
+ return 0;
34
+ }
35
+
36
+ public int showBalance(){ //残高照会
37
+ return balance;
38
+ }
39
+ }
40
+
41
+ ```
42
+ ```java
43
+ import java.io.IOException;
44
+ import java.io.PrintWriter;
45
+ import javax.servlet.ServletException;
46
+ import javax.servlet.http.HttpServlet;
47
+ import javax.servlet.http.HttpServletRequest;
48
+ import javax.servlet.http.HttpServletResponse;
49
+
50
+ public class BankServlet extends HttpServlet {
51
+ private ExtendedBank bank; /* 口座の管理をするオブジェクト */
52
+ public BankServlet() { /* bankを初期化する */
53
+ bank = new ExtendedBank();
54
+ }
55
+
56
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
57
+ throws IOException, ServletException {
58
+ String b_name = request.getParameter("name");
59
+ int result = bank.open(b_name);
60
+ response.setContentType("text/html; charset=UTF-8");
61
+ PrintWriter pw = response.getWriter();
62
+ /* 口座開設処理 */
63
+ if(result == 0) { /* 口座開設成功のHTML生成*/
64
+
65
+ pw.println(
66
+ "<!DOCTYPE html>"
67
+ +"<html>"
68
+ +"<head>"
69
+ +"<meta charset=\"UTF-8\">"
70
+ +"</head>"
71
+ +"<body>"
72
+ +"<div class=\"main\">"
73
+ +"<h1>口座開設成功</h1>"
74
+ +"<h2>+ b_name +様の口座を開設致しました!</h2>"
75
+ +"</div>"
76
+ +"<a class=\"success\" href=\"index.html\">メインメニューに戻る</a>"
77
+ +"</body>"
78
+ +"</html>");
79
+
80
+ } else { /*口座開設失敗のHTML生成 */
81
+
82
+ pw.println(
83
+ "<!DOCTYPE html>"
84
+ +"<html>"
85
+ +"<head>"
86
+ +"<meta charset=\"UTF-8\">"
87
+ +"</head>"
88
+ +"<body>"
89
+ +"<div class=\"main\">"
90
+ +"<h1>口座開設失敗</h1>"
91
+ +"<h2>+ b_name +様の口座は既に存在しております。</h2>"
92
+ +"</div>"
93
+ +"<a class=\"success\" href=\"index.html\">メインメニューに戻る</a>"
94
+ +"</body>"
95
+ +"</html>");
96
+ }
97
+ }
98
+ }
99
+ ```
100
+ ```java
101
+ import java.util.Hashtable;
102
+
103
+ public class ExtendedBank{
104
+ private Hashtable<String,Account>customer; // 口座リスト
105
+ private int balance; // 残高格納用
106
+
107
+ public ExtendedBank(){ // 口座リスト初期化
108
+ customer = new Hashtable<String,Account>();
109
+ }
110
+
111
+ public int open(String name){ // 口座開設
112
+ Account myaccount = customer.get(name);
113
+
114
+ if(customer.get(name) != null) return -7;
115
+ else{
116
+ customer.put(name,new Account(name));
117
+ return 0;
118
+ }
119
+ }
120
+
121
+ public int close(String name){ // 口座解約
122
+ Account myaccount = customer.get(name);
123
+
124
+ if(customer.get(name) != null){
125
+ if(myaccount.showBalance() == 0){
126
+ customer.remove(name);
127
+ return 0;
128
+ }else return -1;
129
+ }else return -7;
130
+ }
131
+
132
+
133
+ public int withdraw(String name,int amount){ // 引き出し
134
+ Account myaccount = customer.get(name);
135
+
136
+ if(customer.get(name) != null){
137
+ if(amount <= 0)
138
+ return -3;
139
+ else if(amount > balance)
140
+ return -1;
141
+ else{
142
+ balance -= amount;
143
+ return 0;
144
+ }
145
+ }else return -7;
146
+ }
147
+
148
+
149
+ public int deposit(String name,int amount){ // 預金
150
+ Account myaccount = customer.get(name);
151
+ if(customer.get(name) == null)
152
+ return -7;
153
+ else if(amount <= 0)
154
+ return -3;
155
+ else{
156
+ balance += amount;
157
+ return 0;
158
+ }
159
+ }
160
+
161
+
162
+ public int showBalance(String name){ // 残高照会
163
+ Account myaccount = customer.get(name);
164
+ if(customer.get(name) != null) return myaccount.showBalance();
165
+ else return -7;
166
+ }
167
+
168
+ // ExtendedBank要素
169
+ // 預金
170
+ public int deposit(String name,String amount){ // name:口座名 d_amount:預金額
171
+ int result;
172
+
173
+ try{
174
+ result = Integer.parseInt(amount);
175
+ }catch(NumberFormatException e){
176
+ if(this.showBalance(name) == -7)
177
+ return -7;
178
+ else
179
+ return -4;
180
+ }
181
+
182
+ result = Integer.parseInt(amount);
183
+ if(result <= 0)
184
+ return -3;
185
+ else{
186
+ balance += result;
187
+ return 0;
188
+ }
189
+ }
190
+
191
+ // 引き出し
192
+ public int withdraw(String name,String amount){ // name:口座名 w_amount:引出額
193
+ int result;
194
+
195
+ try{
196
+ result = Integer.parseInt(amount);
197
+ }catch(NumberFormatException e){
198
+ if(this.showBalance(name) == -7)
199
+ return -7;
200
+ else
201
+ return -4;
202
+ }
203
+
204
+ result = Integer.parseInt(amount);
205
+ if(result <= 0)
206
+ return -3;
207
+ else if(result > balance)
208
+ return -1;
209
+ else{
210
+ balance -= result;
211
+ return 0;
212
+ }
213
+ }
214
+ }
215
+
216
+ ```
217
+ ```java
218
+ import java.io.IOException;
219
+ import java.io.PrintWriter;
220
+ import javax.servlet.ServletException;
221
+ import javax.servlet.http.HttpServlet;
222
+ import javax.servlet.http.HttpServletRequest;
223
+ import javax.servlet.http.HttpServletResponse;
224
+
225
+ public class OpenServlet extends HttpServlet{
226
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
227
+ throws IOException, ServletException {
228
+
229
+ response.setContentType("text/html; charset=UTF-8");
230
+ PrintWriter pw = response.getWriter();
231
+
232
+ pw.println(
233
+ "<!DOCTYPE html>"
234
+ +"<html>"
235
+ +"<head>"
236
+ +"<meta charset=\"utf-8\">"
237
+ +"</head>"
238
+ +"<body>"
239
+ +"<div class=\"main\">"
240
+ +"<h1>口座開設</h1>"
241
+ +"<form action=\"bank\" method=\"GET\">"
242
+ +"<input type=\"hidden\" name=\"command\" value=\"open\">"
243
+ +"<div class=\"input\">"
244
+ +"<label for=\"account\">口座名</label>"
245
+ +"<input type=\"text\" name=\"name\" placeholder=\"入力された口座名\">"
246
+ +"<input type=\"submit\" value = \"確認\">"
247
+ +"</div>"
248
+ +"</form>"
249
+ +"<a class=\"cancel\" href=\"index.html\">キャンセル</a>"
250
+ +"</div>"
251
+ +"</body>"
252
+ +"</html>");
253
+ }
254
+ }
255
+
256
+ ```