I'm using the following code from the book "Head first Servlets & JSP"
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("application/pdf");
ServletContext ctx = getServletContext();
InputStream is = ctx.getResourceAsStream("/download.pdf");
int read=0;
byte[] bytes = new byte[1024];
OutputStream os = resp.getOutputStream();
while((read = is.read(bytes)) != -1){
os.write(bytes, 0, read);
}
}
I've got 2 questions here:
- Why 1024, 10 bits seems like an odd number
- Why does my file download with a filename "download.do.pdf". How do I change this?