質問編集履歴
3
解決
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,115 +1 @@
|
|
1
|
-
jspからある必要なデータをjavaで取得がしたいのですが、画像データもformで飛ばすのでformタグ内にenctype="multipart/form-data"と記述したところjavaでrequest.getParameter();で商品名などのデータが受け取れなく?なった。逆にenctype="multipart/form-data"を外すと、画像を保存する処理がエラーになります
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
```jsp
|
6
|
-
|
7
|
-
コード
|
8
|
-
|
9
|
-
<form action="遷移先java" enctype="multipart/form-data" method = "post">
|
10
|
-
|
11
|
-
<table cellspacing="1" cellpadding="8" border="0" bgcolor="#999999">
|
12
|
-
|
13
|
-
<tr>
|
14
|
-
|
15
|
-
<th width="100" bgcolor="#EBEBEB">コード</th>
|
16
|
-
|
17
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="code" name="code" readonly="readonly" value=""> </td>
|
18
|
-
|
19
|
-
</tr>
|
20
|
-
|
21
|
-
<tr>
|
22
|
-
|
23
|
-
<th width="100" bgcolor="#EBEBEB">商品名<sup><font color="#FF0000">*</font></sup></th>
|
24
|
-
|
25
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="name" name="name" value=""> </td>
|
26
|
-
|
27
|
-
</tr>
|
28
|
-
|
29
|
-
<tr>
|
30
|
-
|
31
|
-
<th width="100" bgcolor="#EBEBEB">金額<sup><font color="#FF0000">*</font></sup></th>
|
32
|
-
|
33
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="unitPrice" name="unitPrice" value=""> </td>
|
34
|
-
|
35
|
-
</tr>
|
36
|
-
|
37
|
-
<tr>
|
38
|
-
|
39
|
-
<th width="100" bgcolor="#EBEBEB">数量<sup><font color="#FF0000">*</font></sup></th>
|
40
|
-
|
41
|
-
<td width="250" bgcolor="#FFFFFF"><input type="text" id="count" name="count" value=""> </td>
|
42
|
-
|
43
|
-
</tr>
|
44
|
-
|
45
|
-
<tr>
|
46
|
-
|
47
|
-
<th width="100" bgcolor="#EBEBEB">商品画像</th>
|
48
|
-
|
49
|
-
<td width="250" bgcolor="#FFFFFF"><input type="file" id="image" name="image"> </td>
|
50
|
-
|
51
|
-
</tr>
|
52
|
-
|
53
|
-
</table>
|
54
|
-
|
55
|
-
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
```java
|
60
|
-
|
61
|
-
コード
|
62
|
-
|
63
|
-
FileItemFactory factory = new DiskFileItemFactory();
|
64
|
-
|
65
|
-
ServletFileUpload upload = new ServletFileUpload(factory);
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Iterator<FileItem> iterator = upload.parseRequest(request).iterator();
|
70
|
-
|
71
|
-
File uploadFile;
|
72
|
-
|
73
|
-
String dirPath = "C:/Users/s_kuroda/Desktop/Workspace/VendingMachine/WebContent/image";
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
while (iterator.hasNext()) {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
FileItem item = iterator.next();
|
82
|
-
|
83
|
-
System.out.println(item);
|
84
|
-
|
85
|
-
if (!item.isFormField()) {
|
86
|
-
|
87
|
-
|
1
|
+
jspからjavaへ値の受け渡しについて、は解決しました。ありがとうございました。
|
88
|
-
|
89
|
-
System.out.println(fileNameWithExt);
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
File filePath = new File(dirPath);
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if (!filePath.exists()) {
|
98
|
-
|
99
|
-
filePath.mkdirs();
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
uploadFile = new File(dirPath);
|
106
|
-
|
107
|
-
item.write(uploadFile);
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
```
|
2
java追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,63 @@
|
|
53
53
|
</table>
|
54
54
|
|
55
55
|
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```java
|
60
|
+
|
61
|
+
コード
|
62
|
+
|
63
|
+
FileItemFactory factory = new DiskFileItemFactory();
|
64
|
+
|
65
|
+
ServletFileUpload upload = new ServletFileUpload(factory);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Iterator<FileItem> iterator = upload.parseRequest(request).iterator();
|
70
|
+
|
71
|
+
File uploadFile;
|
72
|
+
|
73
|
+
String dirPath = "C:/Users/s_kuroda/Desktop/Workspace/VendingMachine/WebContent/image";
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
while (iterator.hasNext()) {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
FileItem item = iterator.next();
|
82
|
+
|
83
|
+
System.out.println(item);
|
84
|
+
|
85
|
+
if (!item.isFormField()) {
|
86
|
+
|
87
|
+
String fileNameWithExt = item.getName();
|
88
|
+
|
89
|
+
System.out.println(fileNameWithExt);
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
File filePath = new File(dirPath);
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
if (!filePath.exists()) {
|
98
|
+
|
99
|
+
filePath.mkdirs();
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
uploadFile = new File(dirPath);
|
106
|
+
|
107
|
+
item.write(uploadFile);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
```
|
1
一部編集
test
CHANGED
File without changes
|
test
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
|
|
4
4
|
|