`
netli
  • 浏览: 76237 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Gwt 同步 文件下载 实现

    博客分类:
  • GWT
 
阅读更多

client

 Button.addClickHandler(new ClickHandler()

{

@Override

public void onClick(ClickEvent event)

{

String select = getSelect();

String url = GWT.getHostPageBaseURL()+"xx.do?select="+select;

final FormPanel form = new FormPanel();

form.setAction(url);

form.setMethod(FormPanel.METHOD_POST);

RootPanel.get().add(form);

FormElement formElement = FormElement.as(form.getElement());

formElement.submit();

 

}

});

 

 

server:

private void writeXml(Document doc, HttpServletResponse response) throws IOException, ServletException

{

 

 

String fileName = "xx.xml"; response.setContentType("application/force-download;charset=UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");

 

BufferedInputStream bis = null; BufferedOutputStream bos = null; try { String docStr = "xxx"; bis = new BufferedInputStream(new StringInputStream(docStr, "utf-8")); bos = new BufferedOutputStream(response.getOutputStream()); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } } catch (FileNotFoundException e) { log.error(e); } finally { if (bos != null) { bos.flush(); bos.close(); } }

 

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics