Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

accessing applets from servlets

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 resides 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 ....
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code looks fine, the problems exists on where you are hosting the components. The servlet is looking for your applet off of ITS root file system. It doesn't know that /home is on a different machine. You need to make the path to the applet the full URL.
In addtion, the servlet will not be able to access the applet on a file system. The applet will need to be hosted on a webserver so the applet can find it.
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try to use fully qualified class name of the applet as the value of code attribute: CODE="packagename.classname.class". Also applet class file should be placed within web application, e.g. web application name is 'test',
then you access servlet via http://hostname :port/test/servlet/Servletname.class
Applet class file should be placed in test/packagename/ folder within your web server. In this case you dont have to mess with CODEBASE attribute value and can leave it to be "."
[ August 11, 2003: Message edited by: Andrey Orekhov ]
Get me the mayor's office! I need to tell him about this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic