01 import java.awt.*;
02 import java.io.*;
03 import javax.servlet.*;
04 import javax.servlet.http.*;
05
06 public class CountDownServlet extends HttpServlet {
07
08 public void doGet(HttpServletRequest req, HttpServletResponse res)
09 throws ServletException, IOException {
10 ServletOutputStream out = res.getOutputStream();
11
12 // pripravíme si multipart response objekt
13 MultipartResponse multi = new MultipartResponse(res);
14
15 // spustíme countdown, môžete si nastaviť vlastné hodnoty
16 for (int i = 3; i > 0; i--) {
17 multi.startResponse("text/plain");
18 out.println(i + "...");
19 multi.endResponse();
20 try { Thread.sleep(3000); } catch (InterruptedException e) { }
21 }
22
23 // na záver pošleme obrázok
24 multi.startResponse("image/gif");
25 try {
26 ServeFile.returnFile(req.getPathTranslated(), out);
27 }
28 catch (FileNotFoundException e) {
29 throw new ServletException("Súbor nenájdený: " + e.getMessage());
30 }
31
32 // ukončíme multipart response
33 multi.finish();
34 }
35 }
|