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

質問編集履歴

5

誤字

2018/09/26 09:21

投稿

mutani
mutani

スコア20

title CHANGED
File without changes
body CHANGED
@@ -278,7 +278,6 @@
278
278
  </html>
279
279
  ```
280
280
  ### 試したこと
281
- ・コンパイルエラーとなるので、エラーにならないように記述したが正常に値を取得できない。
282
281
  ・DAOの時点でslListに値が格納されていない可能性を考慮してコンソール出力したが問題なかった。
283
282
  ### 補足情報
284
283
  このソースコードはクラスの一部であり、ほかにもメソッドがあります。

4

誤字

2018/09/26 09:20

投稿

mutani
mutani

スコア20

title CHANGED
File without changes
body CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  PreparedStatement pstmt = conn.prepareStatement(sql);
30
30
 
31
- //INSERT文中の?に使用する値を設定しSQL完成
31
+ //SELECT文中の?に使用する値を設定しSQL完成
32
32
  pstmt.setInt(1, t_productBean.getproduct_id());
33
33
 
34
34
  //SElECT文を実行し、結果を取得

3

誤字

2018/09/26 08:56

投稿

mutani
mutani

スコア20

title CHANGED
File without changes
body CHANGED
@@ -2,14 +2,13 @@
2
2
  selectで取得した値をリストに格納して、servletを介してJSPに出力する。
3
3
 
4
4
  <詳細>
5
- ソースコード内のslListをservletで取得したいが、コンパイルエラーになる
5
+ ソースコード内のslListをservletで取得したい。
6
6
  servlet内のコードの書き方についてご教示いただけないでしょうか。
7
7
 
8
8
  ### 発生している問題・エラーメッセージ
9
9
 
10
10
  ```
11
11
  ・正常に値を取得できない。
12
- ・またはコンパイルエラーとなり、実行することができない。
13
12
  ```
14
13
 
15
14
  ### 該当のソースコード
@@ -279,7 +278,7 @@
279
278
  </html>
280
279
  ```
281
280
  ### 試したこと
282
- ・コンパイルエラーとなるので、エラーにならないように記述した。
281
+ ・コンパイルエラーとなるので、エラーにならないように記述したが正常に値を取得できない
283
282
  ・DAOの時点でslListに値が格納されていない可能性を考慮してコンソール出力したが問題なかった。
284
283
  ### 補足情報
285
284
  このソースコードはクラスの一部であり、ほかにもメソッドがあります。

2

文保の修正

2018/09/26 08:22

投稿

mutani
mutani

スコア20

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### 該当のソースコード
16
16
 
17
- ```servlet
17
+ ```DAO
18
18
  public List<t_productBean> select(t_productBean t_productBean) {
19
19
 
20
20
  Connection conn = null;
@@ -78,7 +78,8 @@
78
78
  t_productBean t_product = new t_productBean(product_id,product_genre_code,product_name
79
79
  ,product_maker,product_price,product_stock,product_sales,product_remarks);
80
80
 
81
+ System.out.println(
81
- System.out.println("korekore"+t_product.getproduct_id());
82
+ t_product.getproduct_id());
82
83
 
83
84
  slList.add(t_product);
84
85
  }
@@ -102,11 +103,183 @@
102
103
  }
103
104
  ```
104
105
 
106
+ ```servlet
107
+ package servlet;
108
+
109
+ import java.io.IOException;
110
+ import java.util.ArrayList;
111
+ import java.util.List;
112
+
113
+ import javax.servlet.RequestDispatcher;
114
+ import javax.servlet.ServletException;
115
+ import javax.servlet.annotation.WebServlet;
116
+ import javax.servlet.http.HttpServlet;
117
+ import javax.servlet.http.HttpServletRequest;
118
+ import javax.servlet.http.HttpServletResponse;
119
+
120
+ import model.Selectlogic;
121
+ import model.Updatelogic;
122
+ import model.t_productBean;
123
+
124
+ @WebServlet("/ProductUpdate")
125
+ public class ProductUpdate extends HttpServlet {
126
+ private static final long serialVersionUID = 1L;
127
+
128
+ public ProductUpdate() {
129
+ super();
130
+ }
131
+
132
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
133
+ response.setCharacterEncoding("UTF-8");
134
+
135
+ String product_id_parameter = request.getParameter("product_id");
136
+ String product_name = "";
137
+ String product_genre_code = "";
138
+ String product_maker = "";
139
+ int product_price = 0;
140
+ int product_stock= 0;
141
+ int product_sales= 0;
142
+ String product_remarks = "";
143
+
144
+ Integer product_id = Integer.parseInt(product_id_parameter);
145
+
146
+
147
+ t_productBean T_product = new t_productBean(product_id,product_genre_code,product_name
148
+ ,product_maker,product_price,product_stock,product_sales,product_remarks);
149
+
150
+ Selectlogic.execute(T_product);
151
+
152
+ List<t_productBean>productList = new ArrayList<t_productBean>();
153
+ productList.add(new t_productBean(product_id,product_genre_code,product_name,product_maker,product_price,product_stock,product_sales,product_remarks));
154
+
155
+ request.setAttribute("productList", productList);
156
+ RequestDispatcher rd = request.getRequestDispatcher("/ProductUpdate.jsp" );
157
+ rd.forward(request,response);
158
+ }
159
+
160
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
161
+ request.setCharacterEncoding("UTF-8");
162
+
163
+ //formの値を取得
164
+ String product_id_parameter = request.getParameter("product_id");
165
+ String product_genre_code = request.getParameter("product_genre_code");
166
+ String product_name = request.getParameter("product_name");
167
+ String product_maker = request.getParameter("product_maker");
168
+ String product_price_parameter = request.getParameter("product_price");
169
+ String product_stock_parameter = request.getParameter("product_stock");
170
+ String product_sales_parameter = request.getParameter("product_sales");
171
+ String product_remarks = request.getParameter("product_remarks");
172
+
173
+ switch (product_genre_code) {
174
+ case "指定なし":
175
+ product_genre_code ="1";
176
+ break;
177
+
178
+ case "時計":
179
+ product_genre_code ="2";
180
+ break;
181
+
182
+ case "電子機器":
183
+ product_genre_code ="3";
184
+ break;
185
+
186
+ case "携帯":
187
+ product_genre_code ="4";
188
+ break;
189
+ }
190
+
191
+ //String型をintに変換
192
+ Integer product_id = Integer.parseInt(product_id_parameter);
193
+ Integer product_price = Integer.parseInt(product_price_parameter);
194
+ Integer product_stock = Integer.parseInt(product_stock_parameter);
195
+ Integer product_sales = Integer.parseInt(product_sales_parameter);
196
+
197
+
198
+
199
+ //インスタンス化
200
+ t_productBean T_product = new t_productBean(product_id,product_genre_code,product_name
201
+ ,product_maker,product_price,product_stock,product_sales,product_remarks);
202
+
203
+ Updatelogic.execute(T_product);
204
+
205
+ RequestDispatcher dispatcher = request.getRequestDispatcher("/ProductList" );
206
+ dispatcher.forward(request,response);
207
+
208
+ }
209
+ }
210
+ ```
211
+
212
+ ```JSP
213
+ <%@ page language="java" contentType="text/html; charset=UTF-8"
214
+ pageEncoding="UTF-8"%>
215
+ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
216
+ <!DOCTYPE html>
217
+ <html>
218
+ <head>
219
+ <meta charset = "utf-8">
220
+ <title>更新画面</title>
221
+ <link rel="stylesheet" type="text/css" href="css/ProductInfo.css">
222
+ </head>
223
+ <body>
224
+ <form action="" method="post" name="product">
225
+ <table><c:forEach var="productList" items="${productList}">
226
+ <!--商品IDジャンルコード-->
227
+ <tr>
228
+ <th align = "left">商品ID</th><th align = "left">ジャンル</th>
229
+ </tr>
230
+ <tr>
231
+ <td><input name ="product_id" type="text" value="" placeholder="${productList.product_id }"></td><td>
232
+ <select name = "product_genre_code" >
233
+ <option selected>${productList.product_genre_code }</option>
234
+ <option>指定なし</option><option>時計</option><option>電子機器</option><option>携帯</option>
235
+ </select>
236
+ </td>
237
+ </tr>
238
+ <!--商品名メーカー品-->
239
+ <tr>
240
+ <th align = "left">商品名</th><th align = "left">メーカー品</th>
241
+ </tr>
242
+ <tr>
243
+ <td><input name = "product_name" type="text" placeholder=${productList.product_name }></td>
244
+ <td><select name = "product_maker">
245
+ <option selected>${productList.product_maker }</option>
246
+ <option>指定なし</option><option>パナソニック</option><option>ソニー</option><option>シャープ</option>
247
+ </select>
248
+ </td>
249
+ </tr>
250
+ <!--金額と在庫-->
251
+ <tr>
252
+ <th align = "left">金額</th><th align = "left">在庫数</th>
253
+ </tr>
254
+ <tr>
255
+ <td><input name = "product_price" type="text" placeholder=${productList.product_price }></td>
256
+ <td><input name = "product_stock" type="text" placeholder=${productList.product_stock }></td>
257
+ </tr>
258
+ <!--販売個数-->
259
+ <tr>
260
+ <th align="left">販売個数</th>
261
+ </tr>
262
+ <tr>
263
+ <td><input name="product_sales" type="text" placeholder=${productList.product_sales }></td>
264
+ </tr>
265
+ <!--備考テキストエリア-->
266
+ <tr><!--備考-->
267
+ <th align="left">備考</th>
268
+ </tr>
269
+ </c:forEach>
270
+ </table>
271
+ <table>
272
+ <tr><!--テキストエリア-->
273
+ <td><textarea name="product_remarks"></textarea></td>
274
+ </tr>
275
+ </table>
276
+ <input class="sctn" type="image" alt="登録" width="50" height="30" src="img/sc.png" />
277
+ </form>
278
+ </body>
279
+ </html>
280
+ ```
105
281
  ### 試したこと
106
282
  ・コンパイルエラーとなるので、エラーにならないように記述した。
107
283
  ・DAOの時点でslListに値が格納されていない可能性を考慮してコンソール出力したが問題なかった。
108
-
109
-
110
284
  ### 補足情報
111
-
112
285
  このソースコードはクラスの一部であり、ほかにもメソッドがあります。

1

文法の修正

2018/09/26 08:07

投稿

mutani
mutani

スコア20

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### 該当のソースコード
16
16
 
17
- ```JSP
17
+ ```servlet
18
18
  public List<t_productBean> select(t_productBean t_productBean) {
19
19
 
20
20
  Connection conn = null;