Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/9e83b7af587dc05f039af3da93c8edb9 to your computer and use it in GitHub Desktop.
Save ezhov-da/9e83b7af587dc05f039af3da93c8edb9 to your computer and use it in GitHub Desktop.
java servlet отправка файла клиенту
public class GetReportServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ServletContext context = getServletContext();
ServletOutputStream out = resp.getOutputStream();
byte[] byteArray = Files.readAllBytes(path);
//данный контент type говорит что будет файл в формате excel
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
out.write(byteArray);
out.flush();
out.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment