Thanks guys!

Ole

On 09/03/2011 10:51 AM, Konstantin Preißer wrote:
Hi,

-----Original Message-----
From: Jonathan Soons [mailto:jso...@juilliard.edu]
Sent: Saturday, September 03, 2011 2:24 PM
To: Ole Ersoy; Tomcat Users List
Subject: RE: Servlet 3.0 File Upload

You need to add a line in in your form:
<input type="text" name="filename" />

Then in your servlet GetPost() method you put this filename in a
variable:
String filename;
filename = req.getParameter("filename");

Then instead of part.write("samplefile");
do:
part.write(filename);


Doesn't that mean that the user has to enter the filename by himself?

What I usually do to get the filename is:

Part uploadPart = request.getPart("uploadfield"); // get the Part
String contDispoHeader = uploadPart.getHeader("Content-Disposition"); // get 
Content-Disposition header
String uploadFilename = null;
if (contDispoHeader != null) {
        try {
                uploadFilename = new 
ContentDisposition(contDispoHeader).getParameter("filename");
        } catch (ParseException e) { }
}

Note that "ContentDisposition" class is from JavaMail package 
(javax.mail.internet.ContentDisposition). Browser usually send filenames in the 
"filename" parameter of a Content-Disposition header.


Regards,

Konstantin Preißer


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to