posts - 5,  comments - 7,  trackbacks - 0

           

          public String btnSaveXML_action() {
                  
          // TODO: Process the action. Return value is a navigation
                  
          // case name where null will return to the same page.
                  try {
                      
          //get the appId
                      Integer appId = Integer.valueOf(txtMemory1.getText().toString());
                      String appName 
          = datamanagementservice.getAppNameByAppId(appId);
                      Document doc 
          = writeXML(appId, appName);
                      TransformerFactory tFactory 
          = TransformerFactory.newInstance();
                      Transformer transformer 
          = tFactory.newTransformer();
                      DOMSource source 
          = new DOMSource(doc);

                      
          //the file's loadpath
                      String loadPath = "c:\\temp\\" + appName + ".xml";
                      
          //if the file no exist then create it
                      File f = new File("c:\\temp\\");
                      f.mkdirs();
                      StreamResult result 
          = new StreamResult(new java.io.File(loadPath));
                      transformer.transform(source, result);

                      
          //new a download file
                      File t_file = new File(loadPath);
                      
          long l;
                      
          for (l = 0L; l == 0L; l = t_file.length()) {

                          t_file 
          = new File(loadPath);
                      }

                      InputStream in 
          = new FileInputStream(t_file);
                      
          if (in != null{
                          String filename 
          = t_file.getName();
                          filename 
          = java.net.URLEncoder.encode(filename, "utf-8");

                          FacesContext.getCurrentInstance().responseComplete();
                          HttpServletResponse httpServletResponse 
          = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
                          httpServletResponse.reset();
                          httpServletResponse.setContentType(
          "application/x-msdownload");
                          String rrr 
          = "attachment; filename=" + filename;
                          httpServletResponse.setHeader(
          "Content-Disposition", rrr);
                          httpServletResponse.setContentLength((
          int) l);

                          
          byte b[] = new byte[2048];
                          
          for (int len = 0; (len = in.read(b)) > 0;) {
                              httpServletResponse.getOutputStream().write(b, 
          0, len);
                          }

                          in.close();
                      }

                  }
           catch (Exception e) {
                      e.printStackTrace();
                  }

                  getRequestBean1().setSelectAppId((Integer) dropDown1.getSelected());

                  
          return null;
              }
          posted on 2008-11-27 10:39 Vincent-chen 閱讀(260) 評論(0)  編輯  收藏 所屬分類: JSF
          主站蜘蛛池模板: 大同市| 什邡市| 江川县| 松阳县| 丹东市| 栖霞市| 白水县| 新余市| 千阳县| 库车县| 田阳县| 育儿| 铁岭县| 金溪县| 景德镇市| 南康市| 航空| 抚宁县| 桃园市| 永登县| 临洮县| 石城县| 阿拉尔市| 旬邑县| 宁明县| 铁力市| 尉犁县| 文成县| 久治县| 来凤县| 阳曲县| 松潘县| 宜城市| 鄂温| 同江市| 峡江县| 湘乡市| 安宁市| 曲松县| 华阴市| 楚雄市|