• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException

 
bujji adapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam trying to communicate applet and servlet.And iam getting the following exception.
*********************************************
RandomApplet Exception: java.io.FileNotFoundException: http://localhost:8080/se
vlet/RandomServlet?
java.io.FileNotFoundException: http://localhost:8080/servlet/RandomServlet?
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCo
nection.java:549)
at java.net.URL.openStream(URL.java:798)
at GraphApplet.getNumberFromServlet(GraphApplet.java:25)
at GraphApplet.paint(GraphApplet.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:199)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchT
read.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
ad.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
Exception occurred during event dispatching:
java.lang.NullPointerException
at GraphApplet.paint(GraphApplet.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:199)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchT
read.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
ad.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
*************************************************
Here is a small code how iam opening stream in applet.
String urlStr = "http://localhost:8080/servlet/RandomServlet";
url = new URL( urlStr + "?");
InputStream inStream = null;
try{
inStream = url.openStream();
}
catch( IOException e)
{
System.out.println("RandomApplet Exception: " + e.toString());
e.printStackTrace();
return null;
}
************************************************************
Please let me know if iam wrong.
I want somebody to answer my question.
regards
bujji
 
peter johansson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm note quite sure but a common misstake is that one exklude the whole classname when trying to access a servlet. Make sure that you access the servlet(class) using it's hole name(i.e. the servlet lies in a package called "classe", then the url would be "http://localhost:8080/servlet/classes.RandomServlet?")
regards,
/Peter
Originally posted by bujji adapa:
Iam trying to communicate applet and servlet.And iam getting the following exception.
*********************************************
RandomApplet Exception: java.io.FileNotFoundException: http://localhost:8080/se
vlet/RandomServlet?
java.io.FileNotFoundException: http://localhost:8080/servlet/RandomServlet?
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCo
nection.java:549)
at java.net.URL.openStream(URL.java:798)
at GraphApplet.getNumberFromServlet(GraphApplet.java:25)
at GraphApplet.paint(GraphApplet.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:199)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchT
read.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
ad.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
Exception occurred during event dispatching:
java.lang.NullPointerException
at GraphApplet.paint(GraphApplet.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:199)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchT
read.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
ad.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
*************************************************
Here is a small code how iam opening stream in applet.
String urlStr = "http://localhost:8080/servlet/RandomServlet";
url = new URL( urlStr + "?");
InputStream inStream = null;
try{
inStream = url.openStream();
}
catch( IOException e)
{
System.out.println("RandomApplet Exception: " + e.toString());
e.printStackTrace();
return null;
}
************************************************************
Please let me know if iam wrong.
I want somebody to answer my question.
regards
bujji

 
bujji adapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried that.
Still it's complaining the same.
 
Nishith Prabhakar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can think of two things which are possible ...
One obviously ... did you check the servlet ... in the first place is it hosted at that URL ... i am not sure whether this could be the reason ... coz it shud return a Page not found error instead of filenotfoundexception ... anyway ... try accessing the servlet from a browser ...
The second and more probable reason is that the servlet has some error and it does not close the outputstream. So when the client (applet) tries to read the stream its not there. When it says FileNotFoundException, the file it is referring to is the output (reponse) stream from the servlet and not the servlet file itself. The best way to debug would be - remove all processing from the servlet and just return from the doPost or doGet method. If then it does not give an error, the problem is with the servlet code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic