我尝试打开文件时出现零点异常

时间:2013-05-19 18:45:56

标签: java servlets

我想用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;
          }

}

但是当我运行此代码时,我有

这个错误:零点异常

在这一行

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

1 个答案:

答案 0 :(得分:0)

谁致电setServletResponse?似乎没人,所以回复是空的。