tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mantri, Mr Ramesh" <man...@nrlmry.navy.mil>
Subject FileNotFoundException from servlet
Date Thu, 06 Jul 2000 15:24:39 GMT
Dear all,

When we try to send an image file from servlet to applet, for some
reason it is throwing a FileNotFoundException. Do we need to configure
images separately in tomcat? The documentation doesn't say so.

In any case I am appending below a few lines of code. Please take a
look at it and try to identify the source of the problem. All the files
(including image files) are in the proper locations.

Applet:
=======
public class testImage extends JApplet {
   public void init() {
      try {
         URL url = new URL("http://host:port/WEBAPP/servlet/testImage");
         URLConnection con = url.openConnection();
         con.setUseCaches(false);
         ObjectInputStream objStr = 
                new ObjectInputStream(con.getInputStream());
         ImageIcon img = (ImageIcon) objStr.readObject();
         Container cp = getContentPane();
         JLabel lbl = new JLabel(img);
         contentPane.add(lbl);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Servlet
=======
public class testImage extends HttpServlet {
   public void doGet(HttpServletRequest req, HttpServletResponse res)
   throws ServletException, IOException {
      URL url = new URL("http://host:port/WEBAPP/images/someImage.gif");
      ImageIcon img = new ImageIcon(url);
      ObjectOutputStream out = new
ObjectoutputStream(res.getOutputStream());
      out.writeObject(img);
   }
}

Exception Stack Trace
=====================
java.io.FileNotFoundException: http://host:port/WEBAPP/servlet/testImage
..........................
at java.io.IOException.<init>(Compiled Code)
at java.io.FileNotFoundException.<init>(Compiled Code)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Compiled Code)
.............

Also, allow me to add that another test applet and servlet which pass only
String data are working fine. That causes us to suspect that it could be a 
problem caused due to the transmission of image data from servlet to applet.

sincerely,
Ramesh Mantri

Mime
View raw message