URGENT!!!
Hello, can someone help me determine how to change my action class below to accept mulitple files being uploaded?
ACTION CLASS
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward(); // return value
UploadForm uploadForm = (UploadForm) form;
FormFile inputFile = uploadForm.getFile();
String fileName = inputFile.getFileName();
try {
MessageResources mr = getResources(request, "upload");
String location = mr.getMessage("location");
int max_size = NumberUtils.stringToInt(mr.getMessage("size"));
if (inputFile.getFileSize() > max_size) {
ActionErrors errors2 = new ActionErrors();
errors2.add(ActionErrors.GLOBAL_ERROR, new ActionError ("error.maxsize"));
saveErrors(request, errors2);
return mapping.findForward("failure");
}
InputStream inputStream = inputFile.getInputStream();
byte[] fileContents = new byte[inputFile.getFileSize()];
inputStream.read(fileContents);
File outputFile = new File (location + fileName);
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(fileContents);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
ActionErrors errors2 = new ActionErrors();
// Report the error using the appropriate name and ID.
errors2.add(ActionErrors.GLOBAL_ERROR, new ActionError ("error.io"));
saveErrors(request, errors2);
return mapping.findForward("failure");
}
catch (IOException e) {
e.printStackTrace();
ActionErrors errors2 = new ActionErrors();
// Report the error using the appropriate name and ID.
errors2.add(ActionErrors.GLOBAL_ERROR, new ActionError ("error.io"));
saveErrors(request, errors2);
return mapping.findForward("failure");
}
return mapping.findForward("success");
}
}
ACTION FORM
public class UploadForm extends ActionForm
{
private FormFile file1 = null;
private FormFile file2 = null;
private FormFile file3 = null;
/**
* Get file1
* @return FormFile
*/
public FormFile getFile1() {
return file1;
}
/**
* Set file1
* @param <code>FormFile</code>
*/
public void setFile1(FormFile f) {
this.file1 = f;
}
/**
* Get file2
* @return FormFile
*/
public FormFile getFile2() {
return file2;
}
/**
* Set file2
* @param <code>FormFile</code>
*/
public void setFile2(FormFile f) {
this.file2 = f;
}
/**
* Get file3
* @return FormFile
*/
public FormFile getFile3() {
return file3;
}
/**
* Set file3
* @param <code>FormFile</code>
*/
public void setFile3(FormFile f) {
this.file3 = f;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
// Reset values are provided as samples only. Change as appropriate.
file1 = null;
file2 = null;
file3 = null;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
// Validate the fields in your form, adding
// adding each error to this.errors as found, e.g.
// if ((field == null) || (field.length() == 0)) {
// errors.add("field", new org.apache.struts.action.ActionError("error.field.required"));
// }
return errors;
}
}