質問編集履歴

4

初心者アイコンつけた

2016/04/13 07:45

投稿

yuiti926
yuiti926

スコア26

test CHANGED
File without changes
test CHANGED
File without changes

3

jspを見やすいようにしました

2016/04/13 07:45

投稿

yuiti926
yuiti926

スコア26

test CHANGED
File without changes
test CHANGED
@@ -4,23 +4,43 @@
4
4
 
5
5
  コード
6
6
 
7
- <FORM action="BmiAction">身長:<INPUT size="6" type="text" maxlength="4" placeholder="1.8" name="hight" pattern="^([1-9]\d*|0)(\.\d+)?$" required title="小数点以下を含む半角数値のみ受け付けます">m 体重:<INPUT size="6" type="text" maxlength="3" placeholder="68" name="weight" pattern="^[0-9]{2,}" required title="2桁以上の半角数字のみ受け付けます">kg <SELECT class="design-select-box">
8
-
9
- <OPTION>男</OPTION>
10
-
11
- <OPTION>女</OPTION>
12
-
13
- <OPTION>グレイゾーン</OPTION>
14
-
15
-
16
-
17
- </SELECT>
18
-
19
- <INPUT type="submit" value="BMIからオススメ商品を表示→" style="background-color:#ffff99" onmouseover="this.style.background='#99ccff'" onmouseout="this.style.background='#ffff99'" onclick="">
20
-
21
- <BR>あなたのBMI値は<output>0</output>です
22
-
23
- </FORM
7
+ <FORM action="BmiAction">
8
+
9
+ 身長:<INPUT size="6" type="text" maxlength="4" placeholder="1.8"
10
+
11
+ name="hight" pattern="^([1-9]\d*|0)(\.\d+)?$" required
12
+
13
+ title="小数点以下を含む半角数値のみ受け付けます">m
14
+
15
+ 体重:<INPUT size="6"
16
+
17
+ type="text" maxlength="3" placeholder="68" name="weight"
18
+
19
+ pattern="^[0-9]{2,}" required title="2桁以上の半角数字のみ受け付けます">kg
20
+
21
+ <SELECT class="design-select-box">
22
+
23
+ <OPTION>男</OPTION>
24
+
25
+ <OPTION>女</OPTION>
26
+
27
+ <OPTION>グレイゾーン</OPTION>
28
+
29
+
30
+
31
+ </SELECT> <INPUT type="submit" value="BMIからオススメ商品を表示→"
32
+
33
+ style="background-color: #ffff99"
34
+
35
+ onmouseover="this.style.background='#99ccff'"
36
+
37
+ onmouseout="this.style.background='#ffff99'" onclick=""> <BR>あなたのBMI値は
38
+
39
+ <output>0</output>
40
+
41
+ です
42
+
43
+ </FORM>
24
44
 
25
45
  ```
26
46
 

2

actionの中身全部公開

2016/04/13 01:28

投稿

yuiti926
yuiti926

スコア26

test CHANGED
File without changes
test CHANGED
@@ -120,4 +120,122 @@
120
120
 
121
121
  }
122
122
 
123
+
124
+
125
+ /**
126
+
127
+ * 身長情報取得メソッド
128
+
129
+ */
130
+
131
+ public double getHight() {
132
+
133
+ return hight;
134
+
135
+ }
136
+
137
+
138
+
139
+ /**
140
+
141
+ * 身長情報格納メソッド
142
+
143
+ */
144
+
145
+ public void setHight(double hight) {
146
+
147
+ this.hight = hight;
148
+
149
+ }
150
+
151
+
152
+
153
+ /**
154
+
155
+ * 体重情報取得メソッド
156
+
157
+ */
158
+
159
+ public int getWeight() {
160
+
161
+ return weight;
162
+
163
+ }
164
+
165
+
166
+
167
+ /**
168
+
169
+ * 体重情報格納メソッド
170
+
171
+ */
172
+
173
+ public void setWeight(int weight) {
174
+
175
+ this.weight = weight;
176
+
177
+ }
178
+
179
+
180
+
181
+ /**
182
+
183
+ * カロリー情報取得メソッド
184
+
185
+ */
186
+
187
+ public int getKcal() {
188
+
189
+ return kcal;
190
+
191
+ }
192
+
193
+
194
+
195
+ /**
196
+
197
+ * カロリー情報格納メソッド
198
+
199
+ */
200
+
201
+ public void setKcal(int kcal) {
202
+
203
+ this.kcal = kcal;
204
+
205
+ }
206
+
207
+
208
+
209
+ /**
210
+
211
+ * おすすめ商品情報取得メソッド
212
+
213
+ */
214
+
215
+ public List<BMIDTO> getPickupList() {
216
+
217
+ return pickupList;
218
+
219
+ }
220
+
221
+
222
+
223
+ /**
224
+
225
+ * おすすめ商品情報登録メソッド
226
+
227
+ */
228
+
229
+ public void setPickupList(List<BMIDTO> pickupList) {
230
+
231
+ this.pickupList = pickupList;
232
+
233
+ }
234
+
235
+
236
+
237
+ }
238
+
239
+
240
+
123
241
  ```

1

BmiActionのソース追加しました

2016/04/13 01:22

投稿

yuiti926
yuiti926

スコア26

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,99 @@
25
25
  ```
26
26
 
27
27
  見づらくてすいません!
28
+
29
+
30
+
31
+ 下記がform actionのBmiActionの内容です
32
+
33
+ ```java
34
+
35
+ コード public class BmiAction extends ActionSupport{
36
+
37
+
38
+
39
+ /**
40
+
41
+ * シリアルバージョンID
42
+
43
+ */
44
+
45
+ private static final long serialVersionUID = -6470489626126602974L;
46
+
47
+ public double hight;
48
+
49
+ public int weight;
50
+
51
+ public int kcal;
52
+
53
+ public String result=ERROR;
54
+
55
+ public List<BMIDTO> pickupList=new ArrayList<BMIDTO>();
56
+
57
+
58
+
59
+ /**
60
+
61
+ * BMIを算出してお勧めの商品をリストに格納するメソッド
62
+
63
+ * @param hight 身長
64
+
65
+ * @param weight 体重
66
+
67
+ * @param kcal カロリー
68
+
69
+ * @param pickupList おすすめ商品のリスト
70
+
71
+ * @return result 結果
72
+
73
+ */
74
+
75
+ public String execute()throws Exception{
76
+
77
+
78
+
79
+ double bmi = weight/(hight*hight);
80
+
81
+
82
+
83
+
84
+
85
+ if(bmi<25){
86
+
87
+ kcal=1;
88
+
89
+ }if(bmi>30){
90
+
91
+ kcal=3;
92
+
93
+ }else{
94
+
95
+ kcal=2;
96
+
97
+ }
98
+
99
+
100
+
101
+ BmiDAO dao=new BmiDAO();
102
+
103
+ boolean resultDAO=dao.select(kcal);
104
+
105
+
106
+
107
+ if(resultDAO){
108
+
109
+ //pickupList.clear();
110
+
111
+ pickupList.addAll(dao.getPickupList());
112
+
113
+
114
+
115
+ result=SUCCESS;
116
+
117
+ }
118
+
119
+ return result;
120
+
121
+ }
122
+
123
+ ```