This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FIle Upload from Client to Server

 
Nair Anoop
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have written a small EJB and JSP which uploads some user info from a form to the DB. I would also like to upload a file from the user to the server.
Any ideas / resources on how this can be done ?
Thanks.
Anoop
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my company this is known as "the file upload problem".

To perform file uploads, you use a different type of form encoding (offhand it's called multipart/form-data). This means that the handy request.getParameter("xxx"); won't work!

Also problematic is the habit of some app servers (namely iPlanet!) to attempt to parse this kind of form data into name value pairs, and failing, to throw the data away.

However, if you use a 'normal' server (one that isn't buggy in this respect), I'd suggest using the oreilly classes.
http://www.servlets.com/cos/index.html
 
Sergei Voropay
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of writing all the code to deal with multipart form data you probably better off using prebuilt components available from different vendors. Some application servers supply their own classes/components designed specifically for that purpose (i.e. Orion supplies FilePostParser and PostFileInputStream to work with multipart data). You could also use either classes available from o'reilly or a tag-lib from jspSmart.com (jspSmartUpload).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic