首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

简单文件上载

2012-10-18 
简单文件下载前台ext调用方法随便的一个方法名onDeclare : function() {window.open(this.MftDeclHeadActi

简单文件下载
前台ext调用方法  随便的一个方法名

onDeclare : function() {window.open(this.MftDeclHeadAction + this.delcareReplenishManifest+"&manifestId="+this.mftDeclHeadForm.getForm().findField("manifestId").getValue());}

this.MftDeclHeadAction + this.delcareReplenishManifest action 组成访问路径
action层

public ActionForward sendReplenishDoc(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {if (request.getParameter("manifestId") != null) {String mftId = (String)request.getParameter("manifestId");      try {      StringBuffer documentBuffer = this.mftDeclManager.getReplenishDoc(mftId);response.setContentType("application/x-download");      response.setHeader("content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(mftId+".xml", "UTF-8"));byte[] bytes = documentBuffer.toString().getBytes("UTF-8");     BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes));     OutputStream out = new BufferedOutputStream(response.getOutputStream());     int i=-1;while ((i = bis.read()) != -1) {out.write(i);}out.close();bis.close();}catch(Exception e){e.printStackTrace();}}return mapping.findForward("");}


documentBuffer只是返回要下载的文件内容

热点排行