SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile setRepositoryPath

    I need a help at the following program. I get errors marked in red at the code below.

    I use org.appache.commons.fileupload 1.1.1.

    Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.commons.fileupload.*;
    import java.util.*;
    
    public class FileUploadCommons extends HttpServlet{
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
            response.setContentType("text/html");
            PrintWriter out =response.getWriter();
            
            //some html
            out.println("<html>");
            out.print("File upload success.<a href=\"/files/");
            out.print("\">Click here to browse through all uploaded ");
            out.println("files.</a><br>");
            
            ServletContext sc = getServletContext();
            String path=sc.getRealPath("/files");
            org.apache.commons.fileupload.FileUpload fu = new org.apache.commons.fileupload.FileUpload();
            fu.setSizeMax(-1);
            fu.setRepositoryPath(path);         
            try{
                List l = fu.parseRequest(request);
                Iterator i = l.iterator();
                while(i.hasNext()){
                    FileItem fi =  (FileItem)i.next();
                    fi.write(path+"/"+fi.getName());                 
                }
            }
            catch(Exception e){
                throw new ServletException(e);
            }
            
            out.println("</html>");
        }
            public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                doPost(request,response);            
            }
            
        }
    At first red line it says, setRepositoryPath not found at FileUpload
    and
    at the second line it says write(java.io.File) can not be applied to java.lang.String.

    What may I supposed to do? Could you provide a help.
    Tanx so much.
    -1/2=999?

  2. #2
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you seen the appache.commons.fileupload 1.2 release?

    I think setrepositoryPath is in there: http://jakarta.apache.org/commons/fi...index-all.html
    -1/2=999?

  3. #3
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When was 1.2 released, there's no mention on their news page.

  4. #4
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what's wrong?

    That's what I am asking, as I said in the above link [in the page title] it is writen FileUpload 1.2, and setRepositoryPath() is in that page.

    By the way, what's wrong with my code, I got it from J2EE Architecture book.

    Thanks for any help in advance.
    -1/2=999?

  5. #5
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well without bothering to compile your code, your first problem is probably because that method doesn't exist in the version you are using.

    And your second is probably because the method expects a java.io.File object but you're passing it a String object. try write(new File(path + "/" + fi.getName()));

  6. #6
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that the second error has been removed since your suggestion.

    What may I do for the first error? What is fu.setRepositoryPath(path);
    doing actually? How may I change it in some way?

    Tanx so much.
    -1/2=999?

  7. #7
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found that
    setRepositoryPath(String repositoryPath)
    Sets the location used to temporarily store files that are larger than the configured size threshold.
    -1/2=999?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •