Uploading File

Hey Guys,

On my web application i am trying to upload documents such as MS word excel pdf. etc. The application is running from Windows 2003 server. We are sharing a drive of that server in other client machines. If i try to upload a document from a client machine on the network it shows eror that it can't find the document to upload.

I found the problem which say i am trying to upload from may laptop's C drive. since the program is running on server it is looking for the documents on his C drive and obviously the document is not there.

Now can anyone please suggest me what do i have to do so that i can upload a document from any computer and the document doesn't have to be on the server drive. On the internet i found some website that uploads document from other machines such as uploading Word CV's how do they do that.

Can anyone please tell me.

Thanks

[906 byte] By [metallicdreama] at [2007-10-3 0:29:14]
# 1

You want to use a web-form which sends data using the POST method as a multipart request.

You need a servlet to handle this upload.

There is code available from apache to do this, cant remember the link...youll have to google for it.

There is another solution (com.oreilly) which has code to handle this. There is a problem with this site at the moment (I wish I had downloaded and kept a copy now!!) but you could try

http://servlets.com/cos/

and see if the link comes back up.

In short, this solution uses the client browser to send data to the server as part of the request.

angrycata at 2007-7-14 17:22:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Ok, http://servlets.com/cos/ is now back in business, what a relief!!
angrycata at 2007-7-14 17:22:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi! this is vinu@sun.sdn

The next one is just save the link (cos-05Nov2002.zip) on your desktop

and extract and get the cos.jar from lib directory and add that cos.jar jar path in your class path...

and use the code into jsp like i mentioned below:

<%@ page language = "java" import="java.util.*,com.oreilly.servlet.multipart.*" session="true"%>

String sessionFileName = null;

try {

MultipartParser mp = new MultipartParser(request, 10*1024*1024); // 10MB

Part part;

while ((part = mp.readNextPart()) != null) {

String name = part.getName();

if (part.isFile()) {

// it's a file part

FilePart filePart = (FilePart) part;

String fileName = filePart.getFileName();

//System.out.println(fileName);

if (fileName != null) {

// the part actually contained a file

long size = filePart.writeTo(dir);

fileSize = ""+size;

if(name.trim().equals("file1")){

sessionFileName = fileName.trim();

sessionFileNameToUserDisplay = fileName.trim();

}

/* out.println("file: name=" + name + "$; fileName=" + fileName +

", filePath=" + filePart.getFilePath() +

", contentType=" + filePart.getContentType() +

", size=" + size);*/

}

else {

// the field did not contain a file

//out.println("file: name=" + name + "; EMPTY");

}

//out.flush();

}

}

} catch (IOException lEx) {

this.getServletContext().log(lEx, "error reading or saving file");

}

Note: Try the above and u can get that same code from that same website or from the downloaded directory...

vinu@sun.sdna at 2007-7-14 17:22:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
You can also find code example of a servlet and a jsp on http://www.javaatwork.comJohannes
jpostmaa at 2007-7-14 17:22:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...