Multiple File upload

Hi

Im trying to upload two files to the server using JSP.

This is my coding. This is working in the local machine but when i try the same thing remotely it doesn't work.

Pls help me to solve the problem.

Or else give me another example to do multiple file uploads

<%@ page import="java.util.List" %>

<%@ page import="java.util.Iterator" %>

<%@ page import="java.io.File" %>

<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>

<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>

<%@ page import="org.apache.commons.fileupload.*"%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<center><table border="2">

<tr><td><h1>Your files uploaded </h1></td></tr>

<%

boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (!isMultipart)

{

}

else

{

FileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);

List items = null;

try

{

items = upload.parseRequest(request);

}

catch (FileUploadException e)

{

e.printStackTrace();

}

Iterator itr = items.iterator();

while (itr.hasNext())

{

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

if (item.isFormField())

{

} else

{

try {

String itemName = item.getName();

String path = application.getRealPath("/saberlegal/temp//");

File savedFile = new File(application.getRealPath("/saberlegal/temp//"), itemName);

item.write(savedFile);

out.println(itemName);

out.println("<tr><td><b>Your file has been saved at the loaction:</b></td></tr><tr><td><b>"+

application.getRealPath("/saberlegal/temp//")+" "+itemName+"</td></tr>");

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

%>

[2158 byte] By [Randi_octa] at [2007-11-27 9:05:51]
# 1

> application.getRealPath("/saberlegal/temp//")

Does this directory actually exist? You might want to do a check with the File.exists() method, and if it does not exist do a File.mkdirs() before you use the path.

> it doesn't work

You see, this tells us absolutely nothing. You might want to be more specific if you want to get a proper answer. Are you getting an error? Or how is it behaving differently from your expectations?

gimbal2a at 2007-7-12 21:40:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thank you.It works fine when i use the method mkdir().Thank u
Randi_octa at 2007-7-12 21:40:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Im trying to pass the files from a JSP to a Java script and from the JS it calls another JSP which will upload the fils. Here in the first JSP form is a "multipart/form-data" form. There im having another text box to pass the name as well. Here the textbox value doesnt go the the background page. Only the files will be going. If I make the form a normal one text box value is going but not the files.

Pls help

Randi_octa at 2007-7-12 21:40:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...