orangesdk 2011-08-16
GWT下载导入的模板
final FormPanel download = new FormPanel(); download.setAction(GWT.getHostPageBaseURL() + "download"); download.setMethod(FormPanel.METHOD_POST); Button dl = new Button("Download"); dl.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { download.submit(); } });
servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("file download"); String fileName = "ProductImportTemplate.xls"; response.setContentType("application/force-download;charset=UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); // PrintWriter pw = new PrintWriter(response.getOutputStream()); // pw.write("test....."); // pw.flush(); // pw.close(); // String path = request.getContextPath()+"/downloads/ProductImportTemplate.xls"; // System.out.println("path: " + path); // response.sendRedirect(path); }