tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Junghans" <Andreas.Jungh...@fh-karlsruhe.de>
Subject Re: HTML <form>: multipart/form-data
Date Tue, 12 Mar 2002 08:54:02 GMT
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>


Mime
View raw message