質問編集履歴

2

編集

2018/03/03 09:32

投稿

eisaku123
eisaku123

スコア74

test CHANGED
File without changes
test CHANGED
@@ -146,7 +146,7 @@
146
146
 
147
147
 
148
148
 
149
- OutputStream out = response.getOutputStream();//画像側のストリーム<===getOutputStream()はこのレスポンスに対して既に呼び出されています
149
+ OutputStream out = response.getOutputStream();//画像側のストリーム<===エラー:getOutputStream()はこのレスポンスに対して既に呼び出されています
150
150
 
151
151
 
152
152
 

1

編集

2018/03/03 09:32

投稿

eisaku123
eisaku123

スコア74

test CHANGED
File without changes
test CHANGED
@@ -16,6 +16,8 @@
16
16
 
17
17
  ```java
18
18
 
19
+ //①クライント側 アンドロイドアプリ
20
+
19
21
  @Override
20
22
 
21
23
  protected Result doInBackground(Void... voids) {
@@ -113,3 +115,101 @@
113
115
  }
114
116
 
115
117
  ```
118
+
119
+
120
+
121
+ ```java
122
+
123
+ //②サーバー側
124
+
125
+ public class Hello extends HttpServlet{
126
+
127
+
128
+
129
+ @Override
130
+
131
+ public void doGet(
132
+
133
+ HttpServletRequest request,
134
+
135
+ HttpServletResponse response
136
+
137
+ ) throws ServletException, IOException {
138
+
139
+
140
+
141
+ try {
142
+
143
+ response.setContentType("application/octet-stream ;charset=UTF-8");
144
+
145
+ response.setHeader("Content-Disposition" ,"attachment");
146
+
147
+
148
+
149
+ OutputStream out = response.getOutputStream();//画像側のストリーム<===getOutputStream()はこのレスポンスに対して既に呼び出されています
150
+
151
+
152
+
153
+        //////テキスト////////start/////////////////////////////////
154
+
155
+ PrintWriter out2=response.getWriter();//テキスト側のストリーム
156
+
157
+ out2.println("こんにちは777777");
158
+
159
+ //////テキスト////////end/////////////////////////////////
160
+
161
+
162
+
163
+
164
+
165
+ //////画像側////////start/////////////////////////////////
166
+
167
+ FileInputStream input =new FileInputStream("/Applications/Eclipse_4.7.2.app/Contents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/book777/WEB-INF/classes/chapter3/1.jpg");
168
+
169
+
170
+
171
+ int i = input.read();
172
+
173
+ while(i !=-1) {
174
+
175
+ char c = (char)i;
176
+
177
+ out.write(c); //ここでバイナリーデータを流している
178
+
179
+ i = input.read();
180
+
181
+ }
182
+
183
+ input.close();
184
+
185
+ out.close();
186
+
187
+
188
+
189
+ //////画像側////////end/////////////////////////////////
190
+
191
+
192
+
193
+ }catch(Exception e) {
194
+
195
+ System.out.println("意味不明のエラーです");
196
+
197
+ System.out.println(e);
198
+
199
+ }catch (Throwable e) {
200
+
201
+ System.out.println("byte[] data = IOUtils.toByteArray(input);でエラーです");
202
+
203
+ }
204
+
205
+
206
+
207
+ //out.close();
208
+
209
+ }
210
+
211
+
212
+
213
+ }
214
+
215
+ ```