ClassNotFoundException with Applet and Servlet

From: Phil Powell (soazine_at_erols.com)
Date: 02/28/04

  • Next message: Ryan Stewart: "Re: ClassNotFoundException with Applet and Servlet"
    Date: 28 Feb 2004 01:47:17 -0800
    
    

    I have a servlet, NicknameServlet, that is connected via OutputStream
    -> HttpURLConnection object chain from an applet.

    For some bizarre reason, though, the APPLET throws a
    ClassNotFoundException error (and not the servlet!)
    java.lang.ClassNotFoundException: ppowell.NicknameBin

    However, the Applet, not one time, ever addresses even remotely that
    class. In its method populateNickArray() though there is that
    OutputStream -> HttpURLConnection object to the servlet that itself
    instantiates a NicknameBin object.

    If you call the Servlet directly you should receive a serialized
    Vector object:

    http://www.myjavaserver.com/servlet/ppowell.NicknameServlet

    Here is the code to the Servlet:

    [Code]
    /**
     * @version JSDK 1.2
     * @author Phil Powell
     */

    package ppowell;

    import java.io.*;
    import javax.servlet.*;
    import java.util.Vector;
    import javax.servlet.http.*;

    /**
     * This servlet will retrieve the server's JVM-run Singleton instance
    of NicknameBin
     * originally instantiated when the user went through
    chat_validation.jsp
     *
     * @see ChatGlobals, NicknameBin, ChatClient
     */

    public class NicknameServlet extends HttpServlet implements
    Serializable {

     public NicknameServlet() {}

     public void doGet(HttpServletRequest request, HttpServletResponse
    response) {
      this.doPost(request, response);
     }

     public void doPost(HttpServletRequest request, HttpServletResponse
    response) {
      NicknameBin nickBin = NicknameBin.getNicknameBin(); // CREATE OR
    REFER TO SINGLE INSTANCE
      try {
       // DELIVER ENTIRE NICKNAMEBIN AS IS
       ObjectOutputStream out = new
    ObjectOutputStream(response.getOutputStream());
       out.writeObject((Object)nickBin);
       out.flush();
       out.close();
       out = null;
      } catch (IOException e) {
       System.out.println("Could not retrieve NicknameBin instance");
       e.printStackTrace();
      } catch (Exception idunno) {
       idunno.printStackTrace();
      }
     }

    }
    [/Code]

    My question is this: How is it possible for an Applet, that I assume
    is running on your own JVM on your machine, reference a class on a
    remote server running via its own JVM, when there is no direct
    reference to that class from the applet whatsoever? Why is it when
    you call the servlet directly everything's just fine; when you call it
    via the applet you get such a non-sequitur seeming error?

    Thanx
    Phil


  • Next message: Ryan Stewart: "Re: ClassNotFoundException with Applet and Servlet"

    Relevant Pages

    • Re: ClassNotFoundException with Applet and Servlet
      ... > I have a servlet, NicknameServlet, that is connected via OutputStream ... > However, the Applet, not one time, ever addresses even remotely that ... > public void doPost(HttpServletRequest request, ...
      (comp.lang.java.help)
    • servlet/applet communication problem or Linux/Windows trouble ?
      ... frame contains a little form which has the servlet (running on my ... used to load a page with the applet. ... then the servlet listens on port 14444 ... until a connection request is received, and opens a clientSocket. ...
      (comp.lang.java.programmer)
    • Re: applet as servlet BACK end
      ... If I use a socket I'll use some dedicated port for the ... What I was afraid of was the fact that the applet will load from a web ... while the servlet runs on the SAME machine ... execution in the server, which is not what I want. ...
      (comp.lang.java.programmer)
    • Re: whats the referer of an applet ?
      ... applet. ... The applet receives from a servlet an URL of a binary data file. ... But the applet has no referer info. ... request from my new servlet (it verifies the existence of the URL before ...
      (comp.lang.java.programmer)
    • Re: JSP: How to allow servlet and applet to share jar files?
      ... > several library files are used by both the servlet and the applet. ... > in applet.jar and the applet loads classes from both applet.jar and from ... > [I did some googling and looking through applet and JSP docs to try to ...
      (comp.lang.java.programmer)