FileDocCategorySizeDatePackage
ProcessUploadAction.javaAPI DocExample1602Fri Jul 02 11:17:52 BST 2004com.oreilly.strutsckbk.ch07

ProcessUploadAction

public class ProcessUploadAction extends org.apache.struts.action.Action

Fields Summary
Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(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();

		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
            File dir = (File) getServlet().getServletContext().getAttribute("javax.servlet.context.tempdir");
            File f = new File(dir, "test.tmp");
			out = new BufferedOutputStream (new FileOutputStream(f));
	
			byte[] buffer = new byte[512];
            int chars = 0;
			while ((chars = in.read(buffer)) != -1) {
				out.write(buffer, 0, chars);
			}
    }
	  finally {
			if (out != null) out.close();
			if (in != null) in.close();	  	
	  }

		return mapping.findForward("success");