hi matias.
i have asked the same question a couple of weeks ago and charles conover was
kind enough to explain it to me so here's what he has to say:
"
Wilson,
This is very difficult to do. It is funny that the html is so
easy, but actually retrieving the file is so difficult. First, the form
must be a multipart form like this:
<form method="POST" enctype="multipart/form-data"
action="yourfile.html">
I'm afraid I do not know JSP, but only use servlets. For a Servlet
request, I use Jason Hunter's MultipartParser class at
www.servlets.com/cos/javadoc/com/oreilly/servlet/multipart/MultipartPars
er.html
Then, after declaring the MultipartRequest like this:
Multi = new MultipartRequest(req, Directory, maxsize, filename,
OverwriteType);
You have to parse through the parameter names:
Enumeration params = multi.getParameterNames();
<go through enumeration here in a while loop and set your parameters>
Then, get the file names:
Enumeration files = multi.getFileNames();
Then, finally get your file(s):
While (files.hasMoreElements()) {
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
Vars.put(String.valueOf(i),filename);
}
Not easy, huh?
- Chuck
"
or you can also learn how to work with struts framework
http://jakarta.apache.org/struts/
which will do some the work for you
hope this helps
and thanks charles for the answer :>)
wills
Hello,
Is it possible to upload a file to a servlet on a server? I want to parse
the file etc. in the servlet. How do I do it? Is there some other, better
way to solve this?
Please give me some code...
/Mattias
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html