Last active
March 10, 2019 12:15
-
-
Save ezhov-da/9e83b7af587dc05f039af3da93c8edb9 to your computer and use it in GitHub Desktop.
java servlet отправка файла клиенту
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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