File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet can Call an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet can Call an Applet " Watch "Servlet can Call an Applet " New topic

Servlet can Call an Applet

mala H.R.

Joined: Dec 21, 2002
Posts: 4
My Question is when servlet call an applet like this
out.println("<applet code=xyz.class codebase=http://..... width=200 height=400></applet>")
is this works?? if yes kindly tell me where the xyz.class should placed or how should i call an applet class in servlet??
i have placed xyz.class file in the same directory as my servlet class file.
ie. http://url/servlet directory.
what path should i give it to call my applet in servlet.should it be
out.println("<applet code=xyz.class codebase=http://url/servlet/ width=200 height=400></applet>")
or if i place my applet xyz.class in html directory.then how should i give the path. since
both the ways are not working.
it is should applet load: class xyz not found
thanks in advance
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
1. Servlets don't call applets, servlets write HTML pages that have embedded applet tags.
2. Applet classes are loaded by applet rules NOT servlet rules. They are loaded by requests from the browser to the web server so the class files have to be where the web server can serve them. Servers are forbidden to serve files from WEB-INF.
3. A page written by a servlet should look just like a static HTML page when it gets to the browser.
You should start by creating a static page containing your applet and get that running. Then you can work on making your servlet write a page containing the applet tag.
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

In short you just have to use Http Tunneling.
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 231

Originally posted by j_kokil:
In short you just have to use Http Tunneling.

Hi Jignesh,
I am afraid we are not talking about HTTP tunneling here, are we Bill? This query was not about Applet-Servlet communication, the servlets simply creates an APPLET tag. HTTP tunneling is simply a way of bypassing firewall restrictions and enabling Java applets to communicate with the servers.

SCJP2, SCWCD 1.4, PMP, ITIL Foundation
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
As I understand the use of the word, we are not talking about HTTP tunneling when a browser loads an applet by requesting class files from the server. Now, if the applet exchanges data with the server using a HttpURLConnection, I would call it tunneling.
I agree. Here's the link:
subject: Servlet can Call an Applet
It's not a secret anymore!