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

質問編集履歴

2

うまくいかず

2018/02/22 14:31

投稿

eisaku123
eisaku123

スコア77

title CHANGED
File without changes
body CHANGED
@@ -25,4 +25,26 @@
25
25
 
26
26
  }
27
27
  }
28
+ ```
29
+
30
+ 以下のように変えましたがうまくいかず。意味不明。
31
+ 画像のファイル1.jpgは同じ位置にあります。
32
+ ![イメージ説明](b2d3892df1452a321ffe48ee0df66e8a.png)
33
+
34
+ ```java
35
+ public void doGet(
36
+ HttpServletRequest request,
37
+ HttpServletResponse response
38
+ ) throws ServletException, IOException {
39
+ response.setContentType("application/octet-stream");
40
+ response.setHeader("Content-Disposition" ,
41
+ "attachment; filename='1.jpg");//変更
42
+
43
+ OutputStream out = response.getOutputStream();
44
+
45
+ // ここをファイルからbyte[] を取り出してください。
46
+ byte[] downloadData = "1.jpg".getBytes(); //変更 これだとスマホ側に1.jpgのまま出るだけ
47
+ out.write(downloadData);
48
+ out.close();
49
+ }
28
50
  ```

1

ソース編集

2018/02/22 14:30

投稿

eisaku123
eisaku123

スコア77

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  表記の通り、
4
4
 
5
- サーバ(サーブレット)からクライント(Android アプリ)に画像データを送る方法を教えてください。
5
+ サーバ(サーブレット)からクライント(Android アプリ)に画像データを送る方法を教えてください。
6
6
 
7
7
  下記のソースのように文字列は送れるけど、画像ってどういう考えで送れば良いのか思い当たらないです
8
8
 
@@ -12,9 +12,17 @@
12
12
 
13
13
 
14
14
  ```java
15
+ //サーバ側 
16
+ public class Hello extends HttpServlet{
15
17
 
18
+ public void doGet ( HttpServletRequest request, HttpServletResponse response )
19
+ throws ServletException, IOException {
20
+
16
- response.setContentType("image/jpeg; charset=UTF-8");
21
+ response.setContentType("image/jpeg; charset=UTF-8");
17
22
  PrintWriter out = response.getWriter();
18
- out.println("Hello Servle!"); //文字列は送れる
23
+ out.println("Hello Servlet!");  //文字列は送れる
19
-        out.println(**.jpeg); //<--------このような感じ?
24
+ out.println(**.jpeg); //<--------このような感じ?
25
+
26
+ }
27
+ }
20
28
  ```