dcsimg
automated file upload servlet problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ravi_natarajan
Posted On:   Monday, March 18, 2002 02:36 AM

I am writing a servlet for automated file upload.I dont have any problem when I invoke the servlet from my localhost. When I invoke the same servlet on remote I get exception. import java.net.URL; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.io.File; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.BufferedOutputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.IOException; import java.io.StreamCorruptedException; public class FileDownloadTest { public static void main(String[] argv) { try {    More>>

I am writing a servlet for automated file upload.I dont have any problem when I invoke the servlet from my localhost. When I invoke the same servlet on remote I get exception.

			

import java.net.URL;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.StreamCorruptedException;

public class FileDownloadTest {

public static void main(String[] argv)
{
try
{

//String lURL = "http://localhost:8080/test/temp"; //localhost URL
String lURL = "http://remotehost:8080/test/temp"; //remote host URL

URL lClientURL = new URL(lURL);
String lHost = lClientURL.getHost();
File clientFile = new File("C:\Files\winnt256.bmp");

FileInputStream reader = new FileInputStream (clientFile);
String lUpload = "http://"+lHost+":8080/servlet/FileDownloadServlet?"+"FileName="+"winnt256"+"&"+"Ext="+"bmp"+"&"+"URL="+lURL+"&"+"FileLastModified="+new Long(clientFile.lastModified()).toString();
System.out.println(lUpload);
URL lUploadURL = new URL(lUpload);

HttpURLConnection connection = (HttpURLConnection)lUploadURL.openConnection();
// opening the connection for the out put.
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setDefaultUseCaches(false);
connection.setRequestMethod("POST");
//System.out.println("Response code :" +connection.getResponseCode());
OutputStream outputStream =connection.getOutputStream();
long size = clientFile.length();
Long lSize = new Long(size);
byte[] fileContent = new byte[lSize.intValue()];
reader.read(fileContent);
reader.close();
outputStream.write(fileContent);
outputStream.flush();
outputStream.close();
System.out.println(connection.getResponseMessage());
connection.disconnect();
}
catch (StreamCorruptedException sce)
{
sce.printStackTrace();
}
catch (MalformedURLException e)
{
System.out.println("Url specified in not a valid type");
e.printStackTrace();
}
catch(SecurityException e)
{
System.out.println("Cannot access the folder specified in url");
e.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception ");
e.printStackTrace();
}
}
}
   <<Less
About | Sitemap | Contact