This week's book giveaway is in the HTML, CSS and JavaScript forum.
We're giving away four copies of hapi.js in Action and have Matt Harrison on-line!
See this thread for details.
Win a copy of hapi.js in Action this week in the HTML, CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Receive file in Servlet

 
Thomas Greene
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write a Servlet which will get a zip file from the client. Servlet is expected to write the file to the filesystem. 

I am using Postman to simulate the request (attached)


Below is my Servlet code



This gives me the below error



What would be the correct way to receive file from the client and save it on the server?

Thank you
UploadSevletRequest.PNG
[Thumbnail for UploadSevletRequest.PNG]
 
Dave Tolls
Ranch Hand
Posts: 2207
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Files are uploaded using an enc-type of multipart/form-data.
In your servlet you will need something that lets you read in that sort of data.
Simply reading the body won't work.

Apache has the FileUpload package, for example.
 
Tim Moores
Bartender
Posts: 3199
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly recommend to use an existing library for this, like Apache Commons FileUpload. Much better to start with working code than to code all that yourself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!