469,338 Members | 8,112 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

File Upload in J2EE.

dmjpro
2,476 2GB
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=multipart/form-data.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title>Simple File Upload Test</title>
  4.   </head>
  5.   <body>
  6.       <form name = "test_form" method ="POST" enctype="multipart/form-data" action = "../jsp/FileUpload.jsp">
  7.           <input type="file">
  8.           <input type="submit">
  9.       </form>
  10.   </body>
  11. </html>
  12.  
Expand|Select|Wrap|Line Numbers
  1. ServletInputStream in = request.getInputStream();
  2. //Here request is the reference of HttpServletRequest.
  3. byte b[] = new byte[255];
  4. int len;
  5. while((len = in.read(b))!=-1) out.print(new String(b,0,len));
  6.  
My O/P is showing something like this..............!
Expand|Select|Wrap|Line Numbers
  1. -----------------------------5238189273319--
Can't I get the total Content sent by the Browser?

Please help.

Kind regards,
Dmjpro.
Sep 13 '07 #1
6 9004
dmjpro
2,476 2GB
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=multipart/form-data.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title>Simple File Upload Test</title>
  4.   </head>
  5.   <body>
  6.       <form name = "test_form" method ="POST" enctype="multipart/form-data" action = "../jsp/FileUpload.jsp">
  7.           <input type="file">
  8.           <input type="submit">
  9.       </form>
  10.   </body>
  11. </html>
  12.  
Expand|Select|Wrap|Line Numbers
  1. ServletInputStream in = request.getInputStream();
  2. //Here request is the reference of HttpServletRequest.
  3. byte b[] = new byte[255];
  4. int len;
  5. while((len = in.read(b))!=-1) out.print(new String(b,0,len));
  6.  
My O/P is showing something like this..............!
Expand|Select|Wrap|Line Numbers
  1. -----------------------------5238189273319--
Can't I get the total Content sent by the Browser?

Please help.

Kind regards,
Dmjpro.
Somebody please help!

Kind regards,
Dmjpro.
Sep 13 '07 #2
madhoriya22
252 100+
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 servletinputStream.
Sep 13 '07 #3
dmjpro
2,476 2GB
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 servletinputStream.
Thanks to share your knowledges with me.
Nice to see this.
First of all tell me what is Boundary?
When I do enctype=multipart/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 ServletInputStream?

Kind regards,
Dmjpro.
Sep 13 '07 #4
madhoriya22
252 100+
Thanks to share your knowledges with me.
Nice to see this.
First of all tell me what is Boundary?
When I do enctype=multipart/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 ServletInputStream?

Kind regards,
Dmjpro.
Hi,
I think you should use O'reilly's MultipartRequest 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=multipart/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 MultipartRequest api it vill not be required. Google for MultipartRequest or file upload using MultipartRequest you vil get a lot of results.
Sep 13 '07 #5
dmjpro
2,476 2GB
Hi,
I think you should use O'reilly's MultipartRequest 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=multipart/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 MultipartRequest api it vill not be required. Google for MultipartRequest or file upload using MultipartRequest you vil get a lot of results.

Thanks a lot for your kind information.

Kind regards,
Dmjpro.
Sep 13 '07 #6
madhoriya22
252 100+
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 :(
Sep 13 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Amy Kimber | last post: by
15 posts views Thread by Simon | last post: by
3 posts views Thread by Bijoy Naick | last post: by
1 post views Thread by BW | last post: by
3 posts views Thread by Mike Kelly | last post: by
7 posts views Thread by pbd22 | last post: by
3 posts views Thread by shapper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.