Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

O'reilly file upload package  RSS feed

 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I was trying to upload a file using the com.oreilly package from www.servlets.com.I have an html form which accepts from the user the directory he/she wants to save the file on the server.Now when I send the request to the servlet how can I retrieve the parameter for the directory.I am using this constructor

MultipartRequest(javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize)

regards
sanj
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I correctly understand what you are trying to do.....
You have a form that looks something like this:
<form action="<%= fileServletURL %>" method="post" enctype="multipart/form-data">
<td height="50" width="150"><b> File:</b></td>
<input type="file" name="attachment">
<br>
<input type="text" name="path" value="">
<input type="submit" value=" Submit ">
</form>
This creates a MIME document with multiple "parts" -- each part is like an attachment. You have to create a Multi part Object that represents the encoded POST data. (I think you may have to use the MulitiPartParser (it has changed since I used it)) and use the readNextPart() method.
You then go through the parts, looking for you parameter.
It cannot be read directly with a request.getParameter(parameter) method, because it is encoded.
I think that constructor is simply a way to specify where to put the file, if you want to load a destination from a resource bundle, or DB or something, I dont see how it can be used if you have to get the value from the request.
James
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!