File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Has anybody FileUpload.class containing setSizeMax() method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Has anybody FileUpload.class containing setSizeMax() method?

yoman sharma
Greenhorn

Joined: Feb 10, 2005
Posts: 13
Hi actually my servlet code uses FileUpload.setSizeMax() method. But the class file which i have don't posses this method so i am getting the following message everytime


java.lang.NoSuchMethodError: org.apache.commons.fileupload.FileUpload.setSizeMax(I)V
com.jspbook.FileUploadCommons.doPost(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

--------------------------------------------------------
THe servlet code which causes this exception is as follows in which setSizeMax() is called with the help of FileUpload reference.
-------------------------------------------------------


package com.jspbook;

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();

out.println("<html>");
out.print("File upload success. <a href=\"/jspbook/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();
// trim out full path info if it is included
String filename = fi.getName();
int slash = filename.lastIndexOf("\\");
if (slash != -1) {
filename = filename.substring(slash + 1);
}
// write the file to the 'files' directory
fi.write(path+"/"+filename);
}
}
catch (Exception e) {
throw new ServletException(e);
}

out.println("</html>");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
doPost(request, response);
}
}


---------------------------
So please can anybody send me the class file of FileUpload which contains this setSizeMax() method or suggest me a method to resolve this.

THanks in Advance
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://issues.apache.org/bugzilla/show_bug.cgi?id=26305


Do you have struts.jar in your app somewhere?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
yoman sharma
Greenhorn

Joined: Feb 10, 2005
Posts: 13
No i don't have struts.jar
What to do?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This conversation is happening twice in this forum.
I'm closing this copy, the other is here.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Has anybody FileUpload.class containing setSizeMax() method?