tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <ole.er...@gmail.com>
Subject Re: Servlet 3.0 File Upload
Date Tue, 06 Sep 2011 15:07:05 GMT
Thanks guys!

Ole

On 09/03/2011 10:51 AM, Konstantin Preißer wrote:
> Hi,
>
>> -----Original Message-----
>> From: Jonathan Soons [mailto:jsoons@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Mime
View raw message