public org.apache.struts.action.ActionForward | execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
// Get the form file property from the form
UploadForm uploadForm = (UploadForm) form;
FormFile content = uploadForm.getContent();
if (content == null) {
ActionMessage msg = new ActionMessage("error.maxFileSize.exceeded");
ActionMessages errors = new ActionMessages();
errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
saveErrors(request, errors);
return mapping.getInputForward();
}
// continue processing upload ...
InputStream in = null;
OutputStream out = null;
try {
// Get an input stream on the form file
in = content.getInputStream();
// Create an output stream to a file
out = new BufferedOutputStream (new FileOutputStream("temp.txt"));
byte[] buffer = new byte[512];
while (in.read(buffer) != -1) {
out.write(buffer);
}
}
finally {
if (out != null) out.close();
if (in != null) in.close();
}
return mapping.findForward("success");
|