Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help me uploading with jsp

    I used the following code to upload.
    It shows file uploaded but the files are stored in bytes.
    What can i do now?
    I am a beginner and I need a proper solution.
    Code:
    String user=request.getParameter("user");
               String usertype=request.getParameter("user_type");
                            String contentType = request.getContentType();
                            String path=request.getParameter("file");
                            out.println("Content type is :: " +contentType);
                            
                            if ((contentType != null))
                            {
                                
                            DataInputStream in = new DataInputStream(request.getInputStream());
                            int formDataLength = request.getContentLength();
                            byte dataBytes[] = new byte[formDataLength];
                            out.print(dataBytes);
                            int byteRead = 0;
                            int totalBytesRead = 0;
                            while (totalBytesRead < formDataLength)
                            {
                            byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
                            totalBytesRead += byteRead;
                            }
                            String file = new String(dataBytes);
                                                   
                            int lastIndex = contentType.lastIndexOf("=");
                            String boundary = contentType.substring(lastIndex + 1,contentType.length());
                           
                            int startPos =0;
                            int endPos =dataBytes.length;
                            String saveFile = "C:\\Users\\RABBY\\Documents\\NetBeansProjects\\testpage\\web\\"+user+"\\" +path;
                            FileOutputStream fileOut = new FileOutputStream(saveFile);
                           
                            fileOut.write(dataBytes, startPos,endPos);
                            fileOut.flush();
                            fileOut.close();
                            out.println("File saved as " +saveFile);
                            }
    Last edited by zahid0055; 10-11-2012 at 11:39 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •