Results 1 to 5 of 5
  1. #1
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default Upload file in jsp and save it to MYSQL

    I am trying to upload file in jsp.
    I used HTML file tag
    <input type="file" name="resume" size="20" value="Upload Resume ">

    then in second page I retrieved its value by String filepath=request.getParameter("resume");

    But its only giving the file name not the file path.Please someone tell me how i can read file by this and how it can be stored in mysql.

    Thanx in advance!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Upload file in jsp and save it to MYSQL

    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,861
    Rep Power
    19

    Default Re: Upload file in jsp and save it to MYSQL

    You'll want something like Apache FileUpload.
    That'll handle the multipart bit which gives you access to the file stream.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    varunmails is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: Upload file in jsp and save it to MYSQL

    <html>
    <head>
    <title>File Uploading Form</title>
    </head>
    <body>
    <h3>File Upload:</h3>
    Select a file to upload: <br />
    <form action="UploadServlet" method="post"
    enctype="multipart/form-data">
    <input type="file" name="resume" size="50" />
    <br />
    <input type="submit" value="Upload File" />
    </form>
    </body>
    </html>

    -----------
    Servlet part
    ------------

    DataInputStream in = new DataInputStream(request.
    getInputStream());
    //we are taking the length of Content type data
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    //this loop converting the uploaded file into byte code
    while (totalBytesRead < formDataLength) {
    byteRead = in.read(dataBytes, totalBytesRead,
    formDataLength);
    totalBytesRead += byteRead;
    }
    String file = new String(dataBytes);
    //for saving the file name

    Hope then u ll find how to update in DB

  5. #5
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 03-12-2012, 02:03 PM
  2. upload and save file
    By chennee72 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-29-2011, 02:27 PM
  3. Replies: 2
    Last Post: 04-05-2011, 10:19 AM
  4. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  5. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 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
  •