File upload Java code isn't working on the hosting server

23 views Asked by At

I am having trouble getting my jsp code to upload files onto a Linux server. I tested it on my Windows 11 stand-alone server XAMPP and it worked fine, but when I deployed the same code on the Linux server, no file was uploaded into the 'excel' folder. Surprisingly enough, there were no errors in logs either! The only modification that I made to my code was changing the directory of both servers as well as setting up a temp file with "C:\temp". If anyone could help me out with this issue by providing some insight or tips for troubleshooting this problem, that would be much appreciated.

<%
   synchronized(this){
       
        request.setCharacterEncoding("UTF-8");
        String filePath="";
        File file ;
        int maxFileSize = 5000 * 1024;
        int maxMemSize = 5000 * 1024;
        filePath="./jvm/apache-tomcat-7.0.59/domains/kka/excel/";
        String contentType = request.getContentType();
        if (contentType.indexOf("multipart/form-data") >= 0) 
        {
          DiskFileItemFactory factory = new DiskFileItemFactory();
          factory.setSizeThreshold(maxMemSize);
          factory.setRepository(new File(“./temp”));
          ServletFileUpload upload = new ServletFileUpload(factory);
          upload.setSizeMax( maxFileSize );

          try{ 
             List fileItems = upload.parseRequest(request);
             Iterator i = fileItems.iterator();
             while ( i.hasNext () ) 
             {
                FileItem fi = (FileItem)i.next();
                if ( !fi.isFormField () )   
                {
                    String fileName = fi.getName();
                    if( fileName.lastIndexOf("/") >= 0 )
                    {
                        file = new File( filePath + fileName.substring( fileName.lastIndexOf("/"))) ;
                    }else
                    {
                        file = new File( filePath + fileName.substring(fileName.lastIndexOf("/")+1));
                    }
                    fi.write( file ) ;
                }
            }
        }catch(Exception ex) {
                  System.out.println(ex.getMessage());
        }
    }   
        out.print(“File successfully uploaded”);
   }                    
   
 %>
0

There are 0 answers