File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes pass a file from a server to another using servlets or ?!. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "pass a file from a server to another using servlets or ?!." Watch "pass a file from a server to another using servlets or ?!." New topic
Author

pass a file from a server to another using servlets or ?!.

edi kapllani
Greenhorn

Joined: May 09, 2001
Posts: 14
Dear all!
my problem is to pass a file(cripted) which resides in one server to another server.
I wanted to know which would to be the best way to pass it?
At the momment I am using a URL object that calls a servlet passing the Stream that contains the file.
I have tried to use two servlets(passing the stream to the response of the caller and taking it from the request of the other one, but I have got problems with the headers.
thank you!
ciao!


edi<br />SCJP, SCWCD, SCBCD,(SCEA... project to submit)
Sasi Kumar
Greenhorn

Joined: Jan 18, 2002
Posts: 15
Originally posted by edi:
Dear all!
my problem is to pass a file(cripted) which resides in one server to another server.
I wanted to know which would to be the best way to pass it?
At the momment I am using a URL object that calls a servlet passing the Stream that contains the file.
I have tried to use two servlets(passing the stream to the response of the caller and taking it from the request of the other one, but I have got problems with the headers.
thank you!
ciao!
Sasi Kumar
Greenhorn

Joined: Jan 18, 2002
Posts: 15
Hi
Keep the following code as an example. Use the
same code in a servlet or JSP. Pass the URL of
the server where the file resides and run the servlet or jsp in the server , where u have to copy and give the path of that server instead of
"e:\\test.html".

import java.io.*;
import java.net.*;
class StoreJSP{
public static void main(String arg[]){
try{
String urlStr=arg[0];
if(!urlStr.startsWith("http://")){
urlStr="http://" + urlStr;
}
URL urlOb = new URL( urlStr );
URLConnection jspCon = urlOb.openConnection();

// inform the connection that we will send output and accept input
jspCon.setDoInput(true);
//jspCon.setDoOutput(true);
// Don't used a cached version of URL connection.
jspCon.setUseCaches (false);
DataInputStream din=new DataInputStream(jspCon.getInputStream());
//give the server path and the required path instead of e:\\test.html
File f2=new File("e:\\test.html");
FileOutputStream fout= new FileOutputStream(f2);
String str=null;
while((str=din.readLine())!=null ){
for(int i=0;i<str.length();i++){
fout.write( (int)str.charAt(i) );
}
}
}catch(Exception e){
System.out.println(e);
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pass a file from a server to another using servlets or ?!.
 
Similar Threads
how to pass parameters from one container to other container using sendRedirect
Passing control from one application to another.
Sound in servlet output stream
How to redirect an OutputStream
jsp/servlet/container relationships