MultipartRequestWrapper
Shawn Wilson <[email protected]> Fri, 03 Jun 2005 14:01:43 -0600
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format...
------------=_1117828944-3923-182
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I have promoted Stefan's contrib FileUploadRequestWrapper class to
org.barracudamvc.core.helper.servlet.MultipartRequestWrapper, with minor
modifications. The original contrib class, however, still exists.
You would use the MultipartRequestWrapper if you have a form in your
template with enctype="multipart/form-data". This would be used for
example on forms with file upload fields.
Using this wrapper class you can easily support file upload fields using
the Apache Commons FileUpload library as well as all other fields using
a Barracuda FormMap implementation as usual. When writing a control
handler that will accept multipart form data, all that is required is to
wrap the HttpServletRequest in the MultipartRequestWrapper as in the
following example:
class MyEventHandler extends AppEventListener {
public void handleControlEvent(ControlEventContext icontext)
throws EventException, ServletException, IOException {
// wrap the request
MultipartRequestWrapper req = new
MultipartRequestWrapper(icontext.getRequest());
// grab a FileItem (file upload field on the form)
FileItem file = req.getFileItem("upload_field");
// utilize a FormMap for all other fields
MyForm form = new MyForm(); // (extends DefaultFormMap)
form.map(req);
//...
}
}
-shawn
--
=======================================
Shawn A. Wilson [[email protected]]
Senior Software Developer
ATMReports Department, ATM Express Inc.
PH: 877-327-0873, FAX: 406-294-5806
=======================================
------------=_1117828944-3923-182
Content-Type: text/plain; name="message.footer"
Content-Disposition: inline; filename="message.footer"
Content-Transfer-Encoding: 8bit
--
Barracuda mailing list
[email protected]
http://www.objectweb.org/wws/lists/projects/barracuda
------------=_1117828944-3923-182--