Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- how to download file in gae
- public class dumpDataServlet extends HttpServlet {
- public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- String msg = "";
- boolean dumpFile = false;
- JSONObject json = null;
- resp.setCharacterEncoding(Constant.RESPONSE_CHARACTER_ENCODING);
- try {
- try {
- msg = req.getParameter("dumpFile") + " ";
- dumpFile = Boolean.valueOf(req.getParameter("dumpFile"));
- } catch (Exception ex) {
- }json = getFromOtherGAE();
- if (dumpFile) {
- OutputStream out = resp.getOutputStream();
- this.parseExcelFile(json).write(out); //parseExcelFile will return a HSSFWorkbook
- out.flush();
- out.close();
- } else {
- resp.getWriter().println(json.toString());
- }
- } catch (Exception ex) {
- msg = ex.getClass() + " " + ex.getMessage();
- resp.getWriter().println(msg);
- }
- }
- }
- resp.setContentType("application/vnd.ms-excel");
- resp.setHeader("Content-Disposition","attachment; filename=download.xls");
Add Comment
Please, Sign In to add comment