Guest User

Untitled

a guest
Aug 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. how to download file in gae
  2. public class dumpDataServlet extends HttpServlet {
  3. public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  4. String msg = "";
  5. boolean dumpFile = false;
  6. JSONObject json = null;
  7. resp.setCharacterEncoding(Constant.RESPONSE_CHARACTER_ENCODING);
  8. try {
  9. try {
  10. msg = req.getParameter("dumpFile") + " ";
  11. dumpFile = Boolean.valueOf(req.getParameter("dumpFile"));
  12. } catch (Exception ex) {
  13. }json = getFromOtherGAE();
  14. if (dumpFile) {
  15. OutputStream out = resp.getOutputStream();
  16. this.parseExcelFile(json).write(out); //parseExcelFile will return a HSSFWorkbook
  17. out.flush();
  18. out.close();
  19. } else {
  20. resp.getWriter().println(json.toString());
  21. }
  22. } catch (Exception ex) {
  23. msg = ex.getClass() + " " + ex.getMessage();
  24. resp.getWriter().println(msg);
  25. }
  26. }
  27. }
  28.  
  29. resp.setContentType("application/vnd.ms-excel");
  30. resp.setHeader("Content-Disposition","attachment; filename=download.xls");
Add Comment
Please, Sign In to add comment