1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class PDFServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/pdf");
OutputStream out = response.getOutputStream();
File fichier = new File(NOM_DU_FICHIER);
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fichier));
byte[] buffer = new byte[1024];
int read = in.read(buffer, 0, buffer.length);
int i=0;
while (read != -1) {
out.write(buffer, 0, read);
read = in.read(buffer, 0, buffer.length);
}
in.close();
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
} |
Partager