Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 29th, 2007, 01:51 AM
krisgops krisgops is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 1 krisgops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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..

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Commons error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT