On 2/27/06, Roland Schär <[EMAIL PROTECTED]> wrote: > > I've some problems getting fileupload to work within my Struts > environment. I already tried to localize the misconfiguration but i had > no luck so far...all i know is that the while loop does not run at all. > Hope someone of you can help me out.
There is a very high probability that you're hitting the situation in the following FAQ: http://jakarta.apache.org/commons/fileupload/faq.html#parse-in-action-fails -- Martin Cooper Here is a part of my action method i use: > > -- > > import java.util.Iterator; > import java.util.List; > > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import javax.servlet.http.HttpSession; > > import org.apache.commons.fileupload.FileItem; > import org.apache.commons.fileupload.FileItemFactory; > import org.apache.commons.fileupload.disk.DiskFileItemFactory; > import org.apache.commons.fileupload.servlet.ServletFileUpload; > import org.apache.log4j.Logger; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.actions.DispatchAction; > import org.apache.struts.upload.FormFile; > > > > public class ProjectAction extends DispatchAction{ > > private static Logger logger = Logger.getLogger(ProjectAction.class); > private HttpSession httpsession; > > > public ActionForward mtdUpload(ActionMapping mapping, ActionForm > form, HttpServletRequest request, HttpServletResponse response) throws > Exception { > httpsession = request.getSession(true); > > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > List items = upload.parseRequest(request); > > Iterator iter = items.iterator(); > > while(iter.hasNext()) { > logger.debug("Iterating through form items..."); > FileItem item = (FileItem) iter.next(); > if (item.isFormField()) { > //process Form Field > logger.debug("Process form field: " + item.getFieldName > ()); > }else{ > //process Uploaded File > String fileName = item.getName(); > logger.debug("Process file: " + fileName); > File file = new File("C:\\Temp\\"+fileName); > item.write(file); > httpsession.setAttribute("projectFile","File (" + > fileName + ") successfully uploaded."); > } > } > > return (mapping.findForward("frmUpload")); > } > > > } > > > Kind regards > Roland Schär > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
