`

serlvet下载

阅读更多

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
   IOException {
  response.setContentType("application/octet-stream;charset=UTF-8");
  response.setHeader("Connection", "close");
  
  // 由id得到模板信息
  String docPath = "/WEB-INF/classes/com/byd/cmms/web/servlet/MaterialMaintain.xls";
  String realPath = getServletContext().getRealPath(docPath);
  String filename = "MaterialMaintain.xls";
  
  FileInputStream fis = null;
  try { // 写出文件
   response.setHeader("Content-Disposition", "attachment;filename="
     + new String(filename.getBytes("GBK"), "iso8859-1"));//目前windows的编码是GBK
   ServletOutputStream out = response.getOutputStream();
   fis = new FileInputStream(realPath);
   byte[] b = new byte[1024];
   int i = 0;
   while ((i = fis.read(b)) != -1) {
    out.write(b, 0, i);
   }
   out.flush();
   out.close();
  } catch (Exception e) {
   System.out.println(e);
  } finally {
   fis.close();
  }
 }

 

 

private function downloadTemplate():void {
    
    var downloadFileWin:DownloadFileWin = new DownloadFileWin();
    PopUpManager.addPopUp(downloadFileWin,Application.application.mainVS,true);
    downloadFileWin.load("servlet/DownloadTempDoc","MaterialMaintain.xls");
    PopUpManager.centerPopUp(downloadFileWin);
//    var url:String = "servlet/DownloadTempDoc";
//    var request:URLRequest = new URLRequest(url);
//    navigateToURL(request);
   }

 

 

<servlet-mapping>
  <servlet-name>DownloadTempDocServlet</servlet-name>
  <url-pattern>/servlet/DownloadTempDoc</url-pattern>
 </servlet-mapping>

<servlet>
  <servlet-name>DownloadTempDocServlet</servlet-name>
  <servlet-class>com.byd.cmms.web.servlet.DownloadTempDocServlet</servlet-class>
 </servlet>

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics