You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jill Stephenson <ji...@dstc.qut.edu.au> on 2000/08/18 02:09:05 UTC

Re: Problem with urlConnection

I remember having this problem a while back and if I remember 
rightly it was because there was no doPost in my servlet.  I 
think setting doInput to true means use POST rather than GET.

Also you might want to check the contents of your url string 
as the file name in the exception doesn't look like it is 
constructed correctly.

----
Jill

> I am having a problem with opening a urlConnection within a servlet. (I am
> using tomcat 3.1 on NT, Sun JDK1.2.2)  
> 
> Running the follw code segment in a java application work fine but when I
> try it from a servlet I get an exception.
> Does anyone know what I am doing wrong?
> 
> Thanks,
> Steven Bauer
> 
> 
> Code Segment:
> public static String urlconnect(String url) {
>        String results = null;
>        try{
>             URL stockURL = new URL(url);
>             URLConnection c = stockURL.openConnection();
>             
>             c.setUseCaches(true);
>             c.setDoOutput(true);
>             c.setDoInput(true);
> 
>             
>             InputStream is = c.getInputStream();
>                       
>             BufferedReader d = new BufferedReader(new InputStreamReader(is));
>             results = "XML "+c.toString();
>             String rLine;
>             while( (rLine = d.readLine()) != null ) results += rLine +"\n";
>        } catch (Exception e) { e.printStackTrace(); } 
>        return results;
>  } 
> 
> Exception:
> java.io.FileNotFoundException:
> http://shock.tcg.phx.mcd.mot.com/stock/servlet/StockService/?symbols=mot
>         at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.jav
a:530)
>         at aTest.urlconnect(aTest.java:34)
>         at aTest.doGet(aTest.java:51)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
>         at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)
>         at 
org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
>         at 
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
>         at 
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp
12ConnectionHandler.java:156)
>         at 
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
>         at java.lang.Thread.run(Thread.java:479)