Проблема с загрузкой файлов в jsp только на устройствах Apple - PullRequest
0 голосов
/ 03 декабря 2018

Я использую следующий код для загрузки файла с моего сервера (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, но для iPhone (Safari + Chrome) не работает должным образом.быть, он не загружает файл, а показывает мне содержимое файла, как показано ниже.Я не знаю, почему эта проблема происходит.Любая помощь будет по достоинству оценена.error

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...