Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.vigglet.oei.service; import com.vigglet.oei.user.User; import com.vigglet.pdf.ServicePdf; import com.vigglet.servlet.BasePdfServlet; import java.io.File; import java.io.FileInputStream; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; /** * * @author vikn */ @WebServlet("/api/service/download-service-pdf") public class GetServicePdfServlet extends BasePdfServlet { @Override protected void downloadPdf(HttpServletRequest req, HttpServletResponse resp, User user, int modelId) throws Exception { File file = new ServicePdf(ServiceUtil.getInstance().findById(modelId), user).createServiceReport(); resp.setContentLength((int) file.length()); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, resp.getOutputStream()); IOUtils.closeQuietly(fis); } }