This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes O'reilly file upload package Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "O Watch "O New topic
Author

O'reilly file upload package

sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
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

Joined: Aug 28, 2001
Posts: 140
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: O'reilly file upload package
 
Similar Threads
How to create Multipart Request in Java Application
Copying a file using http
FORM Question
uploading servlet
multiple file upload using servlet