Wednesday, January 11, 2012

Web Application to upload a file to any directory

on multipart/form-data:

if you add in the index.jsp

<td><b>Choose the destination directory:</b></td>
<select name="targetDirectory">
<option value="c:/tmp">c:/tmp</option>
<option value="c:/temp">c:/temp</option>

and you do:

Object targetDirectoryAttribute = request.getAttribute("targetDirectory");
String targetDirectoryParameter = request.getParameter("targetDirectory");
System.out.println("targetDirectoryAttribute=" + targetDirectoryAttribute);
System.out.println("targetDirectoryParameter=" + targetDirectoryParameter);

they are both null

on how to read parameters in a multipart/form-data form:

interesting code snippets here

invoke readHeaders() in org.apache.commons.fileupload.MultipartStream

looks too complicated...

I would rather use

getParameter(java.lang.String name)

so I download

but, wait a minute, I find this

Some other posts on the topic:

Eventually I give up on all those horrible libraries, and I add a second for an a onclick javascript to add in the HTTP query the directory info...

See the working result here:

Anyway this is disgusting, the way this HTTP Java Servlet technology turns simple things in a total nightmare.... no wonder people turn to other technologies...

No comments: