• Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet calling an applet  RSS feed

mala H.R.
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am displaying the downline tree of the members using JTree. This program takes the id of the member and generates his downline.the problem is it is showing only the servlet but the applet is not coming. why is it so. i am not able to call this applet directly from html file since it gives nullpointerexception error.i am using servlet since i have to retrieve id of the member from the database. please provide me a solution for this as soon as possible.if there is any other method please give the source code.
thanks in advance
// AccountMember.java
import java.util.*;
public class AccountMember
int id;
String fname,lname,city;
HashSet hs; // can use TreeSet instead of HashSet but Hashset provides faster accessing

public AccountMember(int i,String name,String name1,String city1) {
id = i;
fname = name;
lname = name1;
city = city1;
hs = new HashSet();

public void addMem(AccountMember newmem) {

int getId() { return id; }

String getFname() { return fname; }

String getLname() { return lname; }

String getCity() { return city; }

HashSet getChildSet() { return hs; }

public String toString() { return id + "," + " " + fname + " " + lname + "," + " " + city ; }

boolean hasChild() {
if( hs.size() == 0 )
return false;
else return true;

// MLM.java
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
public class MLM extends JApplet
AccountMember topmost;
DefaultMutableTreeNode rootNode;
DefaultTreeModel treeModel;
JTree tree;
JScrollPane scrollPane;
Container cp;

public void init() {
rootNode = new DefaultMutableTreeNode(topmost);
treeModel = new DefaultTreeModel(rootNode);
tree = new JTree(treeModel);
tree.putClientProperty("JTree.lineStyle", "Angled");
scrollPane = new JScrollPane(tree);
cp = getContentPane();
public void start() {
insertMemNode(topmost, rootNode);
public void assignRoot(AccountMember acmem) {
topmost = acmem;
void insertMemNode(AccountMember parent, DefaultMutableTreeNode parentNode) {
Iterator itr = parent.hs.iterator();
while(itr.hasNext()) {
AccountMember child = (AccountMember)itr.next();
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
treeModel.insertNodeInto(childNode, parentNode, 0);
insertMemNode(child, childNode);
// CheckServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.*;
public class CheckServlet extends HttpServlet
Connection con = null;
ResultSet rs = null;
Statement st = null;
int ref1;
String fname2,lname2,city2;
String fname,lname,city;
AccountMember root;
AccountMember parent;
String fname1;
MLM mlm;
int level;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
PrintWriter out=res.getWriter();

String uid1 = req.getParameter("username3");
String pwd1 = req.getParameter("password3");
String ref = req.getParameter("refno");
ref1 = Integer.parseInt(ref);

out.println("</embed> </object></div></td></tr></table><br>");
try {
con = DriverManager.getConnection("Jdbc dbc:mark");
st = con.createStatement();
ResultSet rs2 = st.executeQuery("select * from paisapayment where accountno='" + ref1 + "'");
while (rs2.next())
fname2 = rs2.getString(3);
lname2 = rs2.getString(4);
city2 = rs2.getString(11);


mlm = new MLM();
root = new AccountMember(ref1,fname2,lname2,city2);

catch(Exception q)
{ q.printStackTrace(); }
//calling an applet from servlet
out.println("<applet codebase = http://localhost/ code = MLM.class width=300 height=300></applet>");

} // End of doPost()
public void ret(AccountMember parent)
try {
con = DriverManager.getConnection("Jdbc dbc:mark);
st = con.createStatement();
int id = parent.getId();
fname = parent.getFname();
lname = parent.getLname();
city = parent.getCity();
ResultSet rs1 = st.executeQuery("select * from paisapayment where referedby='" + id + "' order by accountno");
while (rs1.next())
AccountMember child = new AccountMember(rs1.getInt(1),rs1.getString(3),rs1.getString(4),rs1.getString(11));


catch(Exception q)
}// End of ret(AccountMember)

Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A general idea is if you are getting null pointer exception, it may be connection error or applet creation error. try to capture the errors using exception, say while calling servlet,while initialling applet,while sending back data, etc.,
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mala H.R.:
I am not able to call this applet directly from html file since it gives nullpointerexception error.

Apropos your above statement I looked at the Applet code and it seems you're getting this error beacuse you have not created the AccountMember object "topmost" before using it inside insertMemNode(). Insert a line similar to following in the init() and applet will surely run.

Do tell me if this worked.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!