質問編集履歴
3
解決
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,58 +1,1 @@
|
|
1
|
-
jspからある必要なデータをjavaで取得がしたいのですが、画像データもformで飛ばすのでformタグ内にenctype="multipart/form-data"と記述したところjavaでrequest.getParameter();で商品名などのデータが受け取れなく?なった。逆にenctype="multipart/form-data"を外すと、画像を保存する処理がエラーになります
|
2
|
-
|
3
|
-
```jsp
|
4
|
-
コード
|
5
|
-
<form action="遷移先java" enctype="multipart/form-data" method = "post">
|
6
|
-
<table cellspacing="1" cellpadding="8" border="0" bgcolor="#999999">
|
7
|
-
<tr>
|
8
|
-
<th width="100" bgcolor="#EBEBEB">コード</th>
|
9
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="code" name="code" readonly="readonly" value=""> </td>
|
10
|
-
</tr>
|
11
|
-
<tr>
|
12
|
-
<th width="100" bgcolor="#EBEBEB">商品名<sup><font color="#FF0000">*</font></sup></th>
|
13
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="name" name="name" value=""> </td>
|
14
|
-
</tr>
|
15
|
-
<tr>
|
16
|
-
<th width="100" bgcolor="#EBEBEB">金額<sup><font color="#FF0000">*</font></sup></th>
|
17
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="unitPrice" name="unitPrice" value=""> </td>
|
18
|
-
</tr>
|
19
|
-
<tr>
|
20
|
-
<th width="100" bgcolor="#EBEBEB">数量<sup><font color="#FF0000">*</font></sup></th>
|
21
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="count" name="count" value=""> </td>
|
22
|
-
</tr>
|
23
|
-
<tr>
|
24
|
-
<th width="100" bgcolor="#EBEBEB">商品画像</th>
|
25
|
-
<td width="250" bgcolor="#FFFFFF"><input type="file" id="image" name="image"> </td>
|
26
|
-
</tr>
|
27
|
-
</table>
|
28
|
-
```
|
29
|
-
|
30
|
-
```java
|
31
|
-
コード
|
32
|
-
FileItemFactory factory = new DiskFileItemFactory();
|
33
|
-
ServletFileUpload upload = new ServletFileUpload(factory);
|
34
|
-
|
35
|
-
Iterator<FileItem> iterator = upload.parseRequest(request).iterator();
|
36
|
-
File uploadFile;
|
37
|
-
String dirPath = "C:/Users/s_kuroda/Desktop/Workspace/VendingMachine/WebContent/image";
|
38
|
-
|
39
|
-
while (iterator.hasNext()) {
|
40
|
-
|
41
|
-
FileItem item = iterator.next();
|
42
|
-
System.out.println(item);
|
43
|
-
if (!item.isFormField()) {
|
44
|
-
|
1
|
+
jspからjavaへ値の受け渡しについて、は解決しました。ありがとうございました。
|
45
|
-
System.out.println(fileNameWithExt);
|
46
|
-
|
47
|
-
File filePath = new File(dirPath);
|
48
|
-
|
49
|
-
if (!filePath.exists()) {
|
50
|
-
filePath.mkdirs();
|
51
|
-
}
|
52
|
-
|
53
|
-
uploadFile = new File(dirPath);
|
54
|
-
item.write(uploadFile);
|
55
|
-
|
56
|
-
}
|
57
|
-
}
|
58
|
-
```
|
2
java追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,4 +25,34 @@
|
|
25
25
|
<td width="250" bgcolor="#FFFFFF"><input type="file" id="image" name="image"> </td>
|
26
26
|
</tr>
|
27
27
|
</table>
|
28
|
+
```
|
29
|
+
|
30
|
+
```java
|
31
|
+
コード
|
32
|
+
FileItemFactory factory = new DiskFileItemFactory();
|
33
|
+
ServletFileUpload upload = new ServletFileUpload(factory);
|
34
|
+
|
35
|
+
Iterator<FileItem> iterator = upload.parseRequest(request).iterator();
|
36
|
+
File uploadFile;
|
37
|
+
String dirPath = "C:/Users/s_kuroda/Desktop/Workspace/VendingMachine/WebContent/image";
|
38
|
+
|
39
|
+
while (iterator.hasNext()) {
|
40
|
+
|
41
|
+
FileItem item = iterator.next();
|
42
|
+
System.out.println(item);
|
43
|
+
if (!item.isFormField()) {
|
44
|
+
String fileNameWithExt = item.getName();
|
45
|
+
System.out.println(fileNameWithExt);
|
46
|
+
|
47
|
+
File filePath = new File(dirPath);
|
48
|
+
|
49
|
+
if (!filePath.exists()) {
|
50
|
+
filePath.mkdirs();
|
51
|
+
}
|
52
|
+
|
53
|
+
uploadFile = new File(dirPath);
|
54
|
+
item.write(uploadFile);
|
55
|
+
|
56
|
+
}
|
57
|
+
}
|
28
58
|
```
|
1
一部編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
jspからある必要なデータをjavaで取得がしたいのですが、画像データもformで飛ばすのでformタグ内にenctype="multipart/form-data"と記述したところjavaでrequest.getParameter();で名
|
1
|
+
jspからある必要なデータをjavaで取得がしたいのですが、画像データもformで飛ばすのでformタグ内にenctype="multipart/form-data"と記述したところjavaでrequest.getParameter();で商品名などのデータが受け取れなく?なった。逆にenctype="multipart/form-data"を外すと、画像を保存する処理がエラーになります
|
2
2
|
|
3
3
|
```jsp
|
4
4
|
コード
|