upload Image to server

Hi,I need an example how to upload to Web Server an image using commons-fileuploadRegards
[110 byte] By [the_Orienta] at [2007-11-27 8:39:28]
# 1

I have commons-fileupload-1.2.jar download

[uploadCalss.java]

import org.apache.commons.fileupload.FileItemFactory;

import org.apache.commons.fileupload.FileItem;

import org.apache.commons.fileupload.FileUploadException;

import org.apache.commons.fileupload.servlet.ServletFileUpload;

import org.apache.commons.fileupload.disk.DiskFileItemFactory;

import org.apache.commons.fileupload.DiskFileUpload;

here ist meine klasse

public void doUpload(HttpServletRequest request)

{

int MB = 2 * 1024 * 1024; //Die Maximalgroesse ist 1 MB

String path = "/";

String path = this.savePath;

String contentType = null;

String tmp = null;

String fileName=null;

File tmpFile = null;

FileOutputStream out = null;

DiskFileItemFactory factory = null;

ServletFileUpload upload = null;

List items = null;

FileItem file = null;

try{

tmp = request.getSession().getServletContext().getRealPath("/tmp/");

tmpFile = new File (tmp);

factory = new DiskFileItemFactory();

factory.setSizeThreshold(100*1024);

factory.setRepository(tmpFile);

upload = new ServletFileUpload(factory);

upload.setSizeMax(MB);

items = upload.parseRequest(request);

// here its happen nothing no error, no exception nothing

// What should be the Problem

System.out.println("Found " + items.size() +" items.");

Iterator iter = items.iterator();

while (iter.hasNext()) {

FileItem item = (FileItem)iter.next();

if (!item.isFormField())

{

contentType = item.getContentType();

fileName = item.getName();

System.out.println("fileName: "+fileName);

}

file = item;

}

try

{

file.write(new File(path + fileName));

}catch( Exception ex){ex.printStackTrace();}

}

catch (FileUploadException fue) {

System.out.print("\ncontent.util.filemanager.upload.UploadBean: " + fue);

}

}

Regards

the_Orienta at 2007-7-12 20:37:25 > top of Java-index,Java Essentials,Java Programming...