pass a file from a server to another using servlets or ?!.
edi kapllani
Greenhorn
Joined: May 09, 2001
Posts: 14
posted
0
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
posted
0
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
posted
0
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); } } }