Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 6th, 2008, 01:14 AM
Registered User
 
Join Date: Jun 2008
Location: Ipoh, Perak, Malaysia.
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



        }
      }

}
Reply With Quote
  #2 (permalink)  
Old July 16th, 2008, 04:52 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
http://www.j-nine.com/pubs/applet2se...t2Servlet.html
http://jdj.sys-con.com/read/36044.htm
http://www.theserverside.com/discuss...thread_id=1824


- Rakesh
Reply With Quote
  #3 (permalink)  
Old July 16th, 2008, 05:48 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:32 PM.


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