2012-12-10 83 views
1

在我的Java Web方法應用程序中,我正在選擇一個文件並將其下載。當下載窗口關閉時,我將控件定向回到父頁面。我通過創建IPortletURL調用BasePortletPageBean.createRenderURL()來實現它,將其基URL設置爲我想要重定向的portlet別名。然後調用FacesContext重定向方法。它在Web方法8.0中運行良好,我在Windows XP機器上開發了它。現在我將同一個項目導入到一個安裝了Windows 7的web方法8.2的機器上,但現在它不能正常工作。請幫助我。在java webmethods的下載窗口關閉後無法重定向

public String downloadMaster() { 


    List<Object> selectedRows = getFnamesProvider2().getSelectedRows(); 

    if (getFnamesProvider2().getSelectedRows() != null 
      && getFnamesProvider2().getSelectedRows().size() != 0) { 

     for (Iterator iterator = selectedRows.iterator(); iterator 
       .hasNext();) { 

      com.webmethods.caf.FileNames details = (com.webmethods.caf.FileNames) iterator 
        .next(); 


      System.out.println("Iterator Output!!!!!!!!!!!!!!!!!!!!!!!" 
        + details.toString()); 
      FileInputStream fileInputStream = null; 
      OutputStream out = null; 
      try { 

       String filename = "C:/SoftwareAG/MWS/Projects/" 
         + getProjName() + "/" 
         + session.getAttribute("folder").toString() 
         + "/search/" + details.getFileName(); 

       if (response == null) { 
        response = PortalServlet.getCurrentResponse(); 
        setResponse(response); 
       } 
       if (response.getContentType() == null 
         || (!(response.getContentType() 
           .equalsIgnoreCase("APPLICATION/DOWNLOAD")))) { 
        if (response == null) { 
         response = PortalServlet.getCurrentResponse(); 
        } 
        getResponse().setContentType("APPLICATION/DOWNLOAD"); 
       } 
       response.setHeader("Content-Disposition", "attachment" 
         + "filename=" + details.getFileName()); 

       File fileToDownload = new File(filename); 

       fileInputStream = new FileInputStream(fileToDownload); 
       response.setContentLength(fileInputStream.available()); 
       out = response.getOutputStream(); 
       response.setHeader("Content-Disposition", 
         "attachment;filename=" + details.getFileName()); 

       int i; 
       while ((i = fileInputStream.read()) != -1) { 
        out.write(i); 
       } 
       fileInputStream.close(); 
       out.close(); 

       List<Object> selRows = getFnamesProvider2() 
         .getSelectedRows(); 



      } catch (Exception e) // file IO errors 
      { 
       e.printStackTrace(); 
      } finally { 

       try { 

        IPortletURL renderURL = createRenderUrl(); 

        renderURL.setBaseURL("/kneipp.NewProject"); 
        System.out.println("::::::renderURL::::::" + renderURL); 

        getFacesContext().getExternalContext().redirect(
          renderURL.toString()); 



       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 



      } 


     } 
    } 

    return OUTCOME_OK; 

} 

回答

0

確保您始終使用完整路徑,Webmethods 8.2需要url的完整路徑或任何資源(如圖片)。 這可能是您的問題的原因。

+0

我也試過,但沒用!由於一些直接的要求,我不得不回到WM 8.0 – Cheese