仅在Apple设备上的jsp文件下载问题

时间:2018-12-03 10:45:11

标签: ios iphone pdf

我正在使用以下代码从服务器(jsp)下载文件

 <%     
    if(lang.equals("en")){
    if( ftpdownload((String)pageContext.getAttribute("filename"))){
     //out.println("File in appserver");

    // out.println((String)pageContext.getAttribute("filename"));
str = (String)pageContext.getAttribute("filename");
        String [] filearray=str.split("/",0);
      //response.setContentType("APPLICATION/OCTET-STREAM");
    response.setContentType("application/pdf");
      //response.setHeader("Content-Disposition","attachment; filename="+filearray[2]+ "\"");  
      response.setHeader("Content-Disposition",
"attachment;filename="+filearray[3]);

      java.io.FileInputStream fileInputStream=new java.io.FileInputStream("/NVS_upload/Temporar_one/"+filearray[3]);  

      ServletOutputStream outs = response.getOutputStream();




       int bit = 256;
        int i = 0;
            try {
                    while ((bit) >= 0) {
                        bit = fileInputStream.read();
                        outs.write(bit);
                    }
                        } catch (IOException ioe) {
                        ioe.printStackTrace(System.out);
                    }
                  outs.flush();
                    outs.close();
                   // in.close(); 
      fileInputStream.close(); 
      filedelete("/NVS_upload/Temporar_one/",filearray[3]);

      }
      else{
       response.sendRedirect("/nvs/en/Error/index.html");  
      }}


     if(lang.equals("hi")){
      // String s1 =(String)request.getAttribute("filename_hindi");
     String s1= (String)pageContext.getAttribute("filename_hindi");

      if( (s1==null) || (s1.equals("")) || (s1.equals("NA"))){

      if( ftpdownload((String)pageContext.getAttribute("filename"))){
     //out.println("File in appserver");

    // out.println((String)pageContext.getAttribute("filename"));
 str = (String)pageContext.getAttribute("filename");
        String [] filearray=str.split("/",0);
      response.setContentType("APPLICATION/OCTET-STREAM");

      //response.setHeader("Content-Disposition","attachment; filename="+filearray[2]+ "\"");  
      response.setHeader("Content-Disposition",
"attachment;filename="+filearray[3]);

      java.io.FileInputStream fileInputStream=new java.io.FileInputStream("/NVS_upload/Temporar_one/"+filearray[3]);  

      ServletOutputStream outs = response.getOutputStream();




       int bit = 256;
        int i = 0;
            try {
                    while ((bit) >= 0) {
                        bit = fileInputStream.read();
                        outs.write(bit);
                    }
                        } catch (IOException ioe) {
                        ioe.printStackTrace(System.out);
                    }
                  outs.flush();
                    outs.close();
                   // in.close(); 
      fileInputStream.close(); 
      filedelete("/NVS_upload/Temporar_one/",filearray[3]);

      }
      else{
      //out.println("Error Occurred");
       response.sendRedirect("/nvs/en/Error/index.html");  
      }

      }
      else{
        if( ftpdownload((String)pageContext.getAttribute("filename_hindi"))){
     //out.println("File in appserver");

    // out.println((String)pageContext.getAttribute("filename"));
str = (String)pageContext.getAttribute("filename_hindi");
        String [] filearray=str.split("/",0);
      response.setContentType("APPLICATION/OCTET-STREAM");

      //response.setHeader("Content-Disposition","attachment; filename="+filearray[2]+ "\"");  
      response.setHeader("Content-Disposition",
"attachment;filename="+filearray[3]);

      java.io.FileInputStream fileInputStream=new java.io.FileInputStream("/NVS_upload/Temporar_one/"+filearray[3]);  

      ServletOutputStream outs = response.getOutputStream();




       int bit = 256;
        int i = 0;
            try {
                    while ((bit) >= 0) {
                        bit = fileInputStream.read();
                        outs.write(bit);
                    }
                        } catch (IOException ioe) {
                        ioe.printStackTrace(System.out);
                    }
                  outs.flush();
                    outs.close();
                   // in.close(); 
      fileInputStream.close(); 
      filedelete("/NVS_upload/Temporar_one/",filearray[3]);

      }
      else{
       response.sendRedirect("/nvs/en/Error/index.html");  
      }

      }
      }
      %>

它对于台式机和android上的每个浏览器都完美运行,但对于iPhones(Safari + Chrome)则无法正常运行,它不下载文件而是向我显示文件内容,如下所示。我不知道为什么这个问题发生了。任何帮助将不胜感激。 error

0 个答案:

没有答案