commons-fileupload

I use commoms-file upload to upload an image

in myJsp.jsp

FileItemFactory factory =new DiskFileItemFactory();

ServletFileUpload upload =new ServletFileUpload(factory);

List items = upload.parseRequest(request);// this lone can not interpreted

System.out.println(items)// nothing

No exception

what should bet the problem

regards

ich vesuche items auszugeben aber passiert nichts nicht mal ein exception

was hoennte das Grund sein ?

[633 byte] By [the_Orienta] at [2007-11-27 8:32:44]
# 1
Did you set the form enctype to multipart/form-data?
linxpda_tcolea at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
YES enctype=multipart/form-data
the_Orienta at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Have you tried using DiskFileUpload:List items = (new DiskFileUpload()).parseRequest(rqeuest);System.out.println("Found " + items.size() " items.);...If this doesn't work, can you post the HTML so we can see if there's something going on there?
linxpda_tcolea at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

works not

here is my html code

function getUploadForm(doc)

{

var str='';

//str +='<form id=uploadform name=uploadform action=/biz-4u/UploadServlet?mod=ad method=post enctype=multipart/form-data>';

str +='<form id=uploadform name=uploadform action=../jspFiles/writeFileToServer.jsp?mod=ad method=post enctype=multipart/form-data target=hidden>';

str +='<table cellpading=0 cellspacing=0 width=100%>';

for(var i=0; i < 3;i++){

str +='<tr>';

str +='<td> </td>';

str +='<td><input type=file id=uploadPic'+i+' name=uploadPic'+i+'></td>';

str +='</tr>';

str +='<tr><td colspan=2> </td></tr>';

}

str +='<tr>';

str +='<td> </td>';

str +='<td><button onClick=submitForm(document)>Upload</button></td>';

str +='<td style=width:30px colspan=2> </td>';

str +='</tr>';

str +='</table>';

str +='</form>';

doc.writeln(str);

}

Regards

the_Orienta at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
any help ?
the_Orienta at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

i have no idea what is target=hidden and try putting the post and meta in "" maybe that's as simple as that.. are u trying to do that in a doPost() and not a doGet ? i do it in service and it's OK , here's a header for a form i use and the java code hope it works for you :

<form action="Admin?action=addNewFileArticle" name="myForm" method="POST" enctype="multipart/form-data" >

boolean isMultipart = ServletFileUpload.isMultipartContent(req);

if (isMultipart){

//Create a factory for disk-based file items

DiskFileItemFactory factory = new DiskFileItemFactory();

// Set factory constraints

//factory.setSizeThreshold(yourMaxMemorySize);

File file = new File(dir);

if (!file.exists())

file.createNewFile();

factory.setRepository(file);

// Create a new file upload handler

ServletFileUpload upload = new ServletFileUpload(factory);

//Parse the request

List items = upload.parseRequest(req);

// Process the uploaded items

Iterator iter = items.iterator();

while (iter.hasNext()) {

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

if ((!item.isFormField())&&(item.getName().length()>1)) {

System.out.println("item.getname "+item.getName());

String fileName = item.getName().substring(item.getName().lastIndexOf("\\"),item.getName().length());

File uploadedFile = new File(file.getPath()+"\\"+fileName);

newArticleUrl = uploadedFile.getAbsolutePath();

System.out.println("writing to : "+uploadedFile.getAbsolutePath());

item.write(uploadedFile);

item.getOutputStream().close();

}else{

if (item.getFieldName().equals("articleHeadline")) newArticleHeadline = generalUtils.toUTF8(item.getString());

if (item.getFieldName().equals("articlePreview")) newArticlePreview = generalUtils.toUTF8(item.getString());

if (item.getFieldName().equals("articlePresentable")) newArticlePresentable = generalUtils.toUTF8(item.getString());

}

}

Kernel_77a at 2007-7-12 20:28:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...