This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes accesing applets from servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "accesing applets from servlets" Watch "accesing applets from servlets" New topic

accesing applets from servlets

prabhu kasi

Joined: Aug 06, 2003
Posts: 10
I am trying to access an applet from a servlet .Everytime i run the servlet , it just shows a blank image .The applet contains a pie chart and is compiling well.Can someone tell where i am going wrong .....???servlet is on iplanet and applet on a local machine.
Applet CODE :
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class PieChart extends Applet implements ActionListener
int red, blue, green, yellow;
Label instrutions= new Label("Enter 4 dollar amounts for your
investment portfolio and press ENTER in box 4. ");
Label highRisk = new Label("High Risk");
Label mediumRisk = new Label("Medium Risk");
Label lowRisk = new Label("Low Risk");
Label noRisk = new Label("No Risk");
TextField txtHighRisk = new TextField(" ", 10);
TextField txtMediumRisk = new TextField(" ", 10);
TextField txtLowRisk = new TextField(" ", 10);
TextField txtNoRisk = new TextField(" ", 10);
static private int CIRCLE= 360;
public void init()
public void actionPerformed(ActionEvent thisEvent)

int intHighRisk = Integer.parseInt(txtHighRisk.getText ());
int intMediumRisk = Integer.parseInt
int intLowRisk = Integer.parseInt(txtLowRisk.getText());
int intNoRisk = Integer.parseInt(txtNoRisk.getText());
red = intHighRisk * CIRCLE;
blue = intMediumRisk * CIRCLE;
green = intLowRisk * CIRCLE;
yellow = intNoRisk * CIRCLE;

public void paint(Graphics gr)
gr.fillArc(200, 200, 100, 100, 360, red);
gr.fillArc(200, 200, 100, 100, red, blue);
gr.fillArc(200, 200, 100, 100, blue, yellow);
gr.fillArc(200, 200, 100, 100, yellow, green);
servlet CODE
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PieChartS extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream out = res.getOutputStream();
out.println("<APPLET CODE=\"/home/lnayar/baais/xmlServlet/PieChart.class\" HEIGHT=280 WIDTH=460>");
PLS help me ....
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

The security issues are complex and subtle, so I'm necessarily oversimplifying here, but every sensible Web browser refuses to load an applet using a local path this way -- at least when the HTML the applet is embedded in is coming from a remote server. If this were allowed, it would obviously be a huge security breach just waiting to happen.
The fact that you're using a servlet really doesn't matter; the question is just whether the web browser will load an applet this way or not.
The easiest solution to your immediate problem -- unless you've got some reason why the applet classes need to be on the local disk, in which case you really need to read up on applet security issues -- is to put PieChart.class on the web server, and modify the servlet to emit an http:// or relative link to it instead of an sbsolute file-system path. The browser wants to be able to download the classes from the web server.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: accesing applets from servlets
It's not a secret anymore!