tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bojan Smojver <bo...@binarix.com>
Subject Re: HTML <form>: multipart/form-data
Date Tue, 12 Mar 2002 09:53:43 GMT
That was my first thought as well but I never carried it through, mostly
because I was too lazy to do the RTFM. I guess I can always rewrite my
own parser with the JavaMail stuff.

Thanks for the code...

Bojan

On Tue, 2002-03-12 at 19:54, Andreas Junghans wrote:
> Hi Bojan,
> 
> you can use JavaMail for that. Below is a code snippet that extracts all the
> parts of the form data (probably could need some cleanup though). I don't
> know if this solution works under all circumstances, but we're using it
> regularly with no problems so far.
> 
> Best regards
> 
>   Andreas Junghans
> 
> 
> Properties props = System.getProperties();
> javax.mail.Session session = javax.mail.Session.getDefaultInstance(props,
> null);
> String headers = "Content-Type: " + request.getContentType() + "\r\n\r\n";
> InputStream messageIS = null;
> MimeMessage message = null;
> messageIS = new SequenceInputStream(new
> ByteArrayInputStream(headers.getBytes()), request.getInputStream());
> message = new MimeMessage(session, messageIS);
> 
> MimeMultipart multi = (MimeMultipart) message.getContent();
> int count = multi.getCount();
> int i;
> MimeBodyPart part = null;
> String name;
> String content;
> for (i = 0; i < count; ++i) {
>     part = (MimeBodyPart) multi.getBodyPart(i);
>     disp = part.getHeader("Content-Disposition")[0];
>     name = disp.substring(disp.indexOf("name=\"") + 6);
>     name = name.substring(0, name.indexOf('"'));
>     ...
>     content = (String)part.getContent();
>     ...
> }
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message