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

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]] On Behalf Of
Wilson Edgar
Sent: Tuesday, March 19, 2002 5:51 AM
To: [EMAIL PROTECTED]
Subject: file upload

hi there good people
i have a <form> in my jsp and one of the field is a
<input type=file ....>
to allow the client to brownse through his file system.
My question is quite simple, how can i capture the choosen file and copy
to
a directory in the server.
a practical example would be very much appreciated
thanks in advance for your time
wilson edgar

________________________________________________________________________
___
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

___________________________________________________________________________
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

Reply via email to