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 Murach's Java Servlets and JSP this week in the Servlets 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);
}
}
}
 
 
subject: pass a file from a server to another using servlets or ?!.
 
Similar Threads
jsp/servlet/container relationships
Passing control from one application to another.
How to redirect an OutputStream
how to pass parameters from one container to other container using sendRedirect
Sound in servlet output stream