commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Heinecke <andr...@objectinc.de>
Subject Using FileUpload with Struts
Date Sun, 31 Jul 2005 12:15:36 GMT
Hi,

I encountered a problem with commons FileUpload and Struts. I decided to use 
the commons FileUpload in my struts app because the upload with struts 
(FormFile) isn't serializable. I need it to be serializable because I want to 
make the uploaded file persistent with hibernate.
I found out that using the commons FileUpload will be serializable, since it 
implements the Interface. But how do I integrate it with struts?

Here is what I've done:

I created a multipart-form with tags by struts:
<html:form action="/admin/upload.do" enctype="multipart/form-data">
		<table>
			<tr>
				<td>Titel&#160;</td>
				<td><html:text property="title" size="80" /></td>
			</tr>
			<tr>
				<td>Datei&#160;</td>
				<td><html:file property="file"></html:file> </td>
			</tr>
			<tr>
				<td>&#160;</td>
				<td 
align="right"><html:reset>reset</html:reset>&#160;<html:submit>eintragen</html:submit>
				</td>
			</tr>
		</table>
	</html:form>

The I created to corresponding Form class:
public class UploadForm extends ValidatorForm
{
	private String title;
	private FormFile file;
	
	// getters .. and setters left out for this post

}

This form will be sent to my Action class UploadAction:

Here I am able to retrieve the FormFile ... but thats not serializable

If I try to get the uploaded file as described at FileUpload Homepage, like 
this:

DiskFileUpload upload = new DiskFileUpload();
List<FileItem> items = upload.parseRequest(request);

The returned list is null.

Does anybody allready done something like that?
Any sugesstion is much appreciated!

Thx in advance,

regards

Andreas Heinecke



Mime
View raw message