2013-05-19 64 views
-2

我想打開一個文件的servlet零點異常,當我試圖打開一個文件

我有回到這種類型的byte []

一個功能,我有包含一個按鈕JPS文件當我在這個按鈕這個梅索德(諮詢)點擊將被稱爲 我試試這個代碼

public class Test{ 

    private HttpServletRequest request; 
     private HttpServletResponse response; 

public void consult() { 

     P8Connector connector = new P8Connector(TypeEnum.CE.value(), 
       "test"); 


     GetDocumentsListInFolder getDocumentsListInFolder = new GetDocumentsListInFolder(); 
     List<Document> list = new ArrayList<Document>(); 

     list = getDocumentsListInFolder.execute(connector, 
       "/test", "1"); 


     for (int i = 0; i < list.size(); i++) { 
      Document doc = (Document)list.get(i); 
      GetDocumentContent c = new GetDocumentContent(); 
      byte[] is = c.execute(connector , doc); 


    response.setHeader("Expires", "0"); 
     response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); 
     response.setHeader("Pragma", "public"); 
      response.setContentType("application/pdf"); 
      InputStream in = new FileInputStream("20130114.008.01.pdf"); 
      OutputStream out = response.getOutputStream(); 

      // Copy the bits from instream to outstream 
      byte[] buf = new byte[1024]; 
      int len; 
      while ((len = in.read(buf)) > 0) { 
       out.write(buf, 0, len); 
      } 
      in.close(); 

} 
public void setServletRequest(HttpServletRequest request){ 
      this.request = request; 
      } 

      public HttpServletRequest getServletRequest(){ 
      return request; 
      } 

      public void setServletResponse(HttpServletResponse response){ 
      this.response = response; 
      } 

      public HttpServletResponse getServletResponse(){ 
      return response; 
      } 

} 

但是當我運行這段代碼我有

這ERREUR :零點異常

在這一行

response.setHeader("Expires", "0"); 
+0

響應爲空。你將不得不現在找出原因。 –

+0

您是否調試過以檢查是否正確獲取響應?看來你的問題不在於打開文件操作。 –

回答

0

誰叫setServletResponse?似乎沒有人,所以回覆爲空。

相關問題