Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 6th, 2008, 01:14 AM
Registered User
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to azimdgreat
Default Servlet Call Applet

Hi there,
 I'm new in Java. I have a servlet that want to call applet. It return ClassNotFoundException.
 My coding is below.
package com.csb.ocs.servlet;

import java.applet.Applet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AppletCaller extends HttpServlet {
    private static final long serialVersionUID = 1858939761850073093L;

      static final int WIDTH = 450;
      static final int HEIGHT = 320;
      static final String APPLETNAME = "MainApplet";

      public void doGet(HttpServletRequest req, HttpServletResponse res)
                                   throws ServletException, IOException {
        ServletOutputStream out = res.getOutputStream();

        Applet applet = null;

        try {
          // Load the SecondApplet
          // Must be in the standard CLASSPATH
          try {
            applet = (Applet) Class.forName(APPLETNAME).newInstance();
          catch (Exception e) {
            throw new ServletException("Could not load applet:" + e);

          // Prepare the applet arguments
          String args[] = new String[1];
          args[0] = "barebones=true"; // run without a menu bar

          // Put the applet in its frame
          // addNotify() is called by MainFrameModified

        finally {
          // Clean up resources


Old July 16th, 2008, 04:52 AM
Friend of Wrox
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

You cann't load an applet from inside servlet code. What you can do is write html code which has <applet/> tag to the response object in the servlet. so that the browser where you've called the servlet will parse the html containing <applet/> tag and loads it.

See the following links for more information about Applet-Servlet communication.

- Rakesh
Old July 16th, 2008, 05:48 AM
Friend of Wrox
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

Forgot to mention to make applet communicate with servlet you need to sign the applet. By default applet is not allowed to open a socket or access filesystem for security reasons.

- Rakesh

Similar Threads
Thread Thread Starter Forum Replies Last Post
servlet call using hyperlink tusharkale Servlets 4 October 3rd, 2007 06:02 AM
Applet Servlet Communication pandian Servlets 1 January 23rd, 2006 07:11 AM
Can I call a servlet from a JFram madas Servlets 5 September 26th, 2005 12:52 PM
Applet - Servlet Communication sonishailendra02 Apache Tomcat 0 February 25th, 2005 05:27 AM
How Can I call a HTML file from a servlet? alf.guzman Servlets 3 January 24th, 2005 04:51 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.