title: URL Connection Refused
body: <p>When I run my JSP project local, this code works:</p>
  
  <pre><code>new URL("http://www.example.com").openConnection().getInputStream();
  </code></pre>
  
  <p>When I upload my project to a <code>webserver</code>, I am getting this exception for the code above:</p>
  
  <pre><code>Connection refused
  </code></pre>
  
  <p>I am confused about this because another method that also uses an URL is working fine on the <code>webserver</code>, this one:</p>
  
  <pre><code>URL url = new URL("http://www.example.com");
  BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
  </code></pre>
  
  <p>The URL that is given in the parameters are correct. I can browse to them directly via the browser on my laptop.</p>
  
  <p>I would like to know why the first URL doesn't work on the webserver, and the second one does? And why does the first URL work when running the project local?</p>
  
  <p>The webserver is a Tomcat server.</p>
  
  <p>I checked this thread already: <a href="https://stackoverflow.com/questions/2388138/what-is-a-work-around-for-connection-refused-connect">What is a work around for Connection refused: connect</a></p>