[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Apache JServ- java.lang.ClassNotFoundException: Applet1

I need to have my HttpServlet host an applet (see code below).

The question is where do I put the applet class so that it can be downloaded to the browser?

I have tried htdocs in the Apache webserver directory. I have tried the servlets directory where the servlet is located. All I get is the error java.lang.ClassNotFoundException: Applet1.



The following is my servlet code.

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class TestServlet extends HttpServlet
{
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
    throws ServletException, IOException
  {
    PrintWriter out;

    response.setContentType("text/html");
    out = response.getWriter();

    out.println("<html>");
    out.println("<head><title>This is a test</title></head>");
    out.println("<body>");
    out.println("<h1>Apache works</h1>");
    out.println("<applet");
    out.println("code=Applet1.class");
    out.println("width=800");
    out.println("height=600>");
    out.println("</applet>");
    out.println("</body></html>");
  }
}
0
jmayfield
Asked:
jmayfield
  • 2
  • 2
1 Solution
 
inksystemsCommented:
If you put your applet in default root directory of web server ($APACHE_HOME/htdocs) you should change the line

out.println("code=Applet1.class");

in your code to

out.println("code=/Applet1.class");

Or put .class files in some directory in web server tree, for example $APACHE_HOME/htdocs/applets and change that line to

out.println"code=/applets/Applet1.class");

0
 
mbormannCommented:
so many points for a simple questio ?
:(
0
 
jmayfieldAuthor Commented:
By adding a / in front of Applet1.class, I now get the following:

Error loading class: .Applet1
java.lang.ClassFormatError: Name mismatch: /Applet1 != Applet1
java.lang.ClassNotFoundException: .Applet1

inksystems, thanks for trying. Have you tried what I'm trying on your own. Basically, a servlet that spawns an applet. I am running the server on NT.

As a note to mbormann, by offering so many points, I normally get quick and accurate responses like the one above.
0
 
inksystemsCommented:
Sorry,
add the following line:

out.println("CODEBASE=/");

or

out.println("CODEBASE=/applets");

within APPLET tag.
0
 
jmayfieldAuthor Commented:
Much thanks. Very well done. Thanks for being prompt.

<applet CODEBASE=/ code=Applet1.class>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now