
March 29th, 2007, 01:51 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 1
Time spent in forums: 19 m 52 sec
Reputation Power: 0
|
|
|
Commons error
I tried uploading file using apache commons HttpClient-based file upload using the code given below.
But it works perfectly in my system and when i try the same in my friend's system i get the output as
exception in sendfile..org.apache.commons.httpclient.ConnectTim eoutException: The host did not accept the connection within timeout of 8000 ms
this is the code for Sender.jsp
Code:
<%
try
{
sendFile(ip,f);
} catch(Exception e)
{
out.println("<br>exception in sendfile..");
out.println("<br>"+e.toString());
}
%>
<%!
private void sendFile(String ip, File f) throws HttpException,FileNotFoundException,IOException{
String url ="http://" +ip+ ":8080//gops6//Receiver.jsp";
HttpClient client = new HttpClient();
MultipartPostMethod mPost = new MultipartPostMethod(url);
client.setConnectionTimeout(8000);
mPost.addParameter(f.getName(), f);
int statusCode1 = client.executeMethod(mPost);
//out.println("statusLine>>>" + mPost.getStatusLine());
mPost.releaseConnection();
}
%>
this is the code for Receiver.jsp
Code:
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="org.apache.commons.httpclient.*"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.*"%>
<%
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(1000000);
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
while(itr.hasNext())
{
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField())
{ File f=new File(fi.getName());
File fNew= new File("C:\\Files\\"+f.getName());
fi.write(fNew);
}
}
%>
i tried changing the connection timeout to big values.. still the problem exists but only in my friends pc..
please help..
|