1 |
package dk.thoerup.pictureposterservice; |
2 |
|
3 |
import java.io.FileInputStream; |
4 |
import java.io.IOException; |
5 |
import java.io.OutputStream; |
6 |
|
7 |
import javax.servlet.ServletException; |
8 |
import javax.servlet.http.HttpServlet; |
9 |
import javax.servlet.http.HttpServletRequest; |
10 |
import javax.servlet.http.HttpServletResponse; |
11 |
|
12 |
/** |
13 |
* Servlet implementation class PictureServlet |
14 |
*/ |
15 |
public class PictureServlet extends HttpServlet { |
16 |
private static final long serialVersionUID = 1L; |
17 |
|
18 |
|
19 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
20 |
String pic = request.getParameter("pic"); |
21 |
response.setContentType("image/jpeg"); |
22 |
|
23 |
FileInputStream in = new FileInputStream( "/home/app/data/PicturePoster/" + pic + ".jpeg"); |
24 |
OutputStream out = response.getOutputStream(); |
25 |
|
26 |
|
27 |
int len; |
28 |
byte buf[] = new byte[8192]; |
29 |
while ( (len = in.read(buf)) != -1) { |
30 |
out.write(buf, 0, len); |
31 |
} |
32 |
in.close(); |
33 |
out.close(); |
34 |
|
35 |
} |
36 |
|
37 |
} |