質問編集履歴

2

うまくいかず

2018/02/22 14:31

投稿

eisaku123
eisaku123

スコア74

test CHANGED
File without changes
test CHANGED
@@ -53,3 +53,47 @@
53
53
  }
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ 以下のように変えましたがうまくいかず。意味不明。
60
+
61
+ 画像のファイル1.jpgは同じ位置にあります。
62
+
63
+ ![イメージ説明](b2d3892df1452a321ffe48ee0df66e8a.png)
64
+
65
+
66
+
67
+ ```java
68
+
69
+ public void doGet(
70
+
71
+ HttpServletRequest request,
72
+
73
+ HttpServletResponse response
74
+
75
+ ) throws ServletException, IOException {
76
+
77
+ response.setContentType("application/octet-stream");
78
+
79
+ response.setHeader("Content-Disposition" ,
80
+
81
+ "attachment; filename='1.jpg");//変更
82
+
83
+
84
+
85
+ OutputStream out = response.getOutputStream();
86
+
87
+
88
+
89
+ // ここをファイルからbyte[] を取り出してください。
90
+
91
+ byte[] downloadData = "1.jpg".getBytes(); //変更 これだとスマホ側に1.jpgのまま出るだけ
92
+
93
+ out.write(downloadData);
94
+
95
+ out.close();
96
+
97
+ }
98
+
99
+ ```

1

ソース編集

2018/02/22 14:30

投稿

eisaku123
eisaku123

スコア74

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- サーバ(サーブレット)からクライント(Android アプリ)に画像データを送る方法を教えてください。
9
+ サーバ(サーブレット)からクライント(Android アプリ)に画像データを送る方法を教えてください。
10
10
 
11
11
 
12
12
 
@@ -26,14 +26,30 @@
26
26
 
27
27
  ```java
28
28
 
29
+ //サーバ側 
30
+
31
+ public class Hello extends HttpServlet{
29
32
 
30
33
 
34
+
35
+ public void doGet ( HttpServletRequest request, HttpServletResponse response )
36
+
37
+ throws ServletException, IOException {
38
+
39
+
40
+
31
- response.setContentType("image/jpeg; charset=UTF-8");
41
+ response.setContentType("image/jpeg; charset=UTF-8");
32
42
 
33
43
  PrintWriter out = response.getWriter();
34
44
 
35
- out.println("Hello Servle!"); //文字列は送れる
45
+ out.println("Hello Servlet!");  //文字列は送れる
36
46
 
37
-        out.println(**.jpeg); //<--------このような感じ?
47
+ out.println(**.jpeg); //<--------このような感じ?
48
+
49
+
50
+
51
+ }
52
+
53
+ }
38
54
 
39
55
  ```