File Upload in J2EE.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    File Upload in J2EE.

    Have a look at my HTML Code and my Java code.
    I m trying to see the total contents when a form is submitted with enctype=multipa rt/form-data.

    [code=html]
    <html>
    <head>
    <title>Simple File Upload Test</title>
    </head>
    <body>
    <form name = "test_form" method ="POST" enctype="multip art/form-data" action = "../jsp/FileUpload.jsp" >
    <input type="file">
    <input type="submit">
    </form>
    </body>
    </html>
    [/code]

    [code=java]
    ServletInputStr eam in = request.getInpu tStream();
    //Here request is the reference of HttpServletRequ est.
    byte b[] = new byte[255];
    int len;
    while((len = in.read(b))!=-1) out.print(new String(b,0,len) );
    [/code]

    My O/P is showing something like this........... ...!
    Code:
    -----------------------------5238189273319--
    Can't I get the total Content sent by the Browser?

    Please help.

    Kind regards,
    Dmjpro.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by dmjpro
    Have a look at my HTML Code and my Java code.
    I m trying to see the total contents when a form is submitted with enctype=multipa rt/form-data.

    [code=html]
    <html>
    <head>
    <title>Simple File Upload Test</title>
    </head>
    <body>
    <form name = "test_form" method ="POST" enctype="multip art/form-data" action = "../jsp/FileUpload.jsp" >
    <input type="file">
    <input type="submit">
    </form>
    </body>
    </html>
    [/code]

    [code=java]
    ServletInputStr eam in = request.getInpu tStream();
    //Here request is the reference of HttpServletRequ est.
    byte b[] = new byte[255];
    int len;
    while((len = in.read(b))!=-1) out.print(new String(b,0,len) );
    [/code]

    My O/P is showing something like this........... ...!
    Code:
    -----------------------------5238189273319--
    Can't I get the total Content sent by the Browser?

    Please help.

    Kind regards,
    Dmjpro.
    Somebody please help!

    Kind regards,
    Dmjpro.

    Comment

    • madhoriya22
      Contributor
      • Jul 2007
      • 251

      #3
      Originally posted by dmjpro
      Somebody please help!

      Kind regards,
      Dmjpro.
      Hi,
      I output is printing the boundary value.

      Are you sure by doing this you are getting the file from the client. How you are binding that file into servletinputStr eam.

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by madhoriya22
        Hi,
        I output is printing the boundary value.

        Are you sure by doing this you are getting the file from the client. How you are binding that file into servletinputStr eam.
        Thanks to share your knowledges with me.
        Nice to see this.
        First of all tell me what is Boundary?
        When I do enctype=multipa rt/form-data in a form Tag then in which format the data comes into the server?
        And where should I do binding the file into ServletInputStr eam?

        Kind regards,
        Dmjpro.

        Comment

        • madhoriya22
          Contributor
          • Jul 2007
          • 251

          #5
          Originally posted by dmjpro
          Thanks to share your knowledges with me.
          Nice to see this.
          First of all tell me what is Boundary?
          When I do enctype=multipa rt/form-data in a form Tag then in which format the data comes into the server?
          And where should I do binding the file into ServletInputStr eam?

          Kind regards,
          Dmjpro.
          Hi,
          I think you should use O'reilly's MultipartReques t api to upload the file. what you need to do is ........ download the jar file from here http://www.servlets.com/cos/ Here you find the api for file upload and by a little searching you find jar also. You can use apache's JCommon for file download also.

          Boundary is a value which is attached with headers while sending file from client(I think so).

          When you do enctype=multipa rt/form-data your data comes in multipart format but for that your html page should support RFC encoding.
          Binding of file should be done on server side. But I really dont know how you should do that. But if you vil use MultipartReques t api it vill not be required. Google for MultipartReques t or file upload using MultipartReques t you vil get a lot of results.

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by madhoriya22
            Hi,
            I think you should use O'reilly's MultipartReques t api to upload the file. what you need to do is ........ download the jar file from here http://www.servlets.com/cos/ Here you find the api for file upload and by a little searching you find jar also. You can use apache's JCommon for file download also.

            Boundary is a value which is attached with headers while sending file from client(I think so).

            When you do enctype=multipa rt/form-data your data comes in multipart format but for that your html page should support RFC encoding.
            Binding of file should be done on server side. But I really dont know how you should do that. But if you vil use MultipartReques t api it vill not be required. Google for MultipartReques t or file upload using MultipartReques t you vil get a lot of results.

            Thanks a lot for your kind information.

            Kind regards,
            Dmjpro.

            Comment

            • madhoriya22
              Contributor
              • Jul 2007
              • 251

              #7
              Originally posted by dmjpro
              Thanks a lot for your kind information.

              Kind regards,
              Dmjpro.
              Hi,
              Binding of file should be done at client side not at server side. Sorry :(

              Comment

              Working...