2016-04-20 19 views
1

私のコードはサーバーjspからアクセスしています。クライアントマシンにある別のjspにアクセスしています。しかし、私のサーバーJSPが外部のオフィス(別のネットワーク)と私のネットワークのクライアントにあるときと同じコードは、サーバーログに接続タイムアウト例外が発生しています。 そして、私はクライアントマシンにajax呼び出しで接続すると、応答フォームのclient.Myコードを取得することができます。下にいくつかの問題が明確になっていますか?サーバーのJSPでURLConnectionを使用してアクセス中に接続タイムアウトが発生しました

Javaコード:働いているサーバーのJSPで

URL jspUrl = new URL("...../Test.jsp"); 
    URLConnection servletConnection = jspUrl.openConnection(); 
    servletConnection.setDoOutput(true); 
    servletConnection.setDoInput(true); 
    servletConnection.setUseCaches(true); 
    servletConnection.setDefaultUseCaches(true); 
    servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object"); 
    OutputStream outputStream = servletConnection.getOutputStream(); 
    ObjectOutputStream outputToServlet = new ObjectOutputStream(outputStream); 
    outputToServlet.writeObject(object); 
    outputToServlet.flush(); 

    InputStream inputStream = servletConnection.getInputStream(); 
    ObjectInputStream outputFromServlet = new ObjectInputStream(inputStream); 
    readObject = outputFromServlet.readObject(); 
    outputFromServlet.close(); 
    outputToServlet.close(); 

Ajaxコード:すべての

 function callAjax 
     { 
      if(window.XMLHttpRequest) 
      { 
       reqObj=new XMLHttpRequest(); 
      } 
      else 
      { 
       reqObj=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      reqObj.onreadystatechange=processfunction; 
      reqObj.open("POST","./jspName.jsp?"+Id,false); 
      reqObj.send(null); 
     } 
    function processfunction() 
    { 
     try 
     { 
      if(reqObj.readyState==4) 
      { 
       if(reqObj.status == 200) 
       { 
        var responseString = reqObj.responseText; 

       } 
      } 
     } 
     catch(e) 
     { 
      //alert(e); 
     } 

    } 
+0

の可能性のある重複[接続時間をURLConnectionのを使用してJSPにアクセスしている間](https://stackoverflow.com/questions/36723057/connection-time-out-while-accessing -jsp-using-urlconnection) – devpuh

答えて

0

まず、あなたがインターネットに接続されていることを確認してください。そして、すなわちinfinteゼロに接続時間を変更します。

servletConnection.setConnectTimeout(0); 

//Set read time out to zero if required 
servletConnection.setReadTimeout(0); 
関連する問題