Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 08:05 AM   PM User | #1
zahid0055
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
zahid0055 is an unknown quantity at this point
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 10:39 AM..
zahid0055 is offline   Reply With Quote
Reply

Bookmarks

Tags
error, help uploading, jsp, upload

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:35 AM.


Advertisement
Log in to turn off these ads.