CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Help me uploading with jsp (http://www.codingforums.com/showthread.php?t=276112)

zahid0055 10-11-2012 08:05 AM

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);
                        }



All times are GMT +1. The time now is 07:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.