This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File Upload  RSS feed

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new to Java servlet. How can I upload a file with servlet?

Thanks & best regards
 
Jan Cumps
Bartender
Posts: 2628
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Farakh,

There is a special forum for Servlet questions. In it's FAQ, there is a link to several FileUpload approaches.

Regards, Jan
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a long search on the web I found the following class workable but I have three main problems:

1. It shows other parameters as null e.g. below
String uname=request.getParameter("uname");
out.println(uname);

2. It overwrites the file if the filename already exists

3. It saves two copies one on c and other on bin of tomcat e.g.
null contact.jpg
contact.jpg
C:\Program Files\Java\tomcat\bin\.\contact.jpg
null

Thanks & best regards




[BPSouther: Fixed code tags]
[ March 28, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Farakh khan:
After a long search on the web I found the following class workable ...


Why the long search on the web?
Jan gave you a link to our FAQ which lists the most commonly used upload libraries. Most of us are using the jakarta commons upload library which is very easy to start out with.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


Why the long search on the web?
Jan gave you a link to our FAQ which lists the most commonly used upload libraries. Most of us are using the jakarta commons upload library which is very easy to start out with.


being a beginner everything seems me difficult right now but may be with passage of time things became easier for me

I got this example very easy but facing the 3 major problems as I mentioned earlier. Please advise me

I really appreciate this forum that whenever I posted any question I got reply immediately. Thanks a lot. Really I am learning too much from this forum

Thanks again
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used the O'Reilly libraries in years so I can't answer all of your questions but as to getParameter returning null...

This is normal.
When using upload libraries, request.getParameter doesn't work (the post from the browser is in a different format and the library has to parse it itself). You'll need to check the library's documentation to see how to retrieve normal form parameters.
[ March 28, 2008: Message edited by: Ben Souther ]
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
I haven't used the O'Reilly libraries in years so I can't answer all of your questions but as to getParameter returning null...

This is normal.
When using upload libraries, request.getParameter doesn't work (the post from the browser is in a different format and the library has to parse it itself). You'll need to check the library's documentation to see how to retrieve normal form parameters.

[ March 28, 2008: Message edited by: Ben Souther ]


Thanks for your reply
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried now the apache fileupload package. I am trying to upload file in db.

The following code throws error that:
FileUpload.java:53: reached end of file while parsing
}
1 error

Thanks & best regards




[BSouther: Added UBB CODE tags]
[ March 30, 2008: Message edited by: Ben Souther ]
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can You please check my above code

Thanks & best regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!