Ola, estou utlizando o fileUpload
ao executar da erro na seguinte linha
List lista = upload.parseRequest(req, intTamanho, lngTamanho, “c:\temp”);
eu depurei pelo eclipse, o que esta errado??
a pasta temp existe.
meu classpath
C:\projeto\WEB-INF\lib\commons-fileupload-1.1-dev.jar
parece que ele nao consegue achar algo.
erro:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.commons.fileupload.DefaultFileItemFactory.createItem(DefaultFileItemFactory.java:102)
org.apache.commons.fileupload.FileUploadBase.createItem(FileUploadBase.java:488)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:359)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:266)
org.apache.commons.fileupload.DiskFileUpload.parseRequest(DiskFileUpload.java:207)
FileServlet.doPost(FileServlet.java:45)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
[code]public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
boolean isMultipart =false;
int intTamanho=1024*20;
long lngTamanho=1024*20;
String strCaminho ="/file";
if (isMultipart=FileUpload.isMultipartContent(req)){
try {
DiskFileUpload upload = new DiskFileUpload();
List lista = upload.parseRequest(req, intTamanho, lngTamanho, "c:\temp");
System.out.println(lista.size());
Iterator it = lista.iterator();
FileItem fi = (FileItem) it.next();
while(it.hasNext()){
File diretorio=new File(strCaminho);
if (!diretorio.exists()){
diretorio.mkdir();
}
File file=new File(diretorio, fi.getName());
FileOutputStream fos=new FileOutputStream(file);
InputStream is=fi.getInputStream();
byte[] buffer=new byte[2048];
int nLidos;
while ((nLidos=is.read(buffer))>=0){
fos.write(buffer,0,nLidos);
}
fos.flush();
fos.close();
System.out.println(file.getAbsolutePath());
}
} catch ( FileUploadException e){
e.printStackTrace();
}
} [/code]