FileDocCategorySizeDatePackage
UploadAction.javaAPI DocExample1806Wed Apr 05 20:04:10 BST 2006com.oreilly.ajax

UploadAction

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

Fields Summary
static String
productsDirectory
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)

    UploadForm myForm = (UploadForm)form;
    int productId = myForm.getProductId();
    
    // Process the FormFile
    FormFile myFile = myForm.getUploadFile();
    String fileName = myFile.getFileName();
    byte[] fileData = myFile.getFileData();

    FileOutputStream out = new FileOutputStream(getFilePath()+"/"+fileName);

    out.write(fileData);
    out.close();
    ProductManager.updateProductById(productId,"FILENAME",fileName);

    return mapping.findForward("success");
  
private java.lang.StringgetFilePath()


     
        String resourceFilepath = this.getServlet().getServletContext().getRealPath("/shopping.properties");
        Properties configs = new Properties();
        configs.load(new FileInputStream(resourceFilepath));
        String dir = this.getServlet().getServletContext().getRealPath("")+"/"+configs.getProperty("products.directory");
        return dir;