Hi all,
I am trying to invoke a
servlet from an
applet. The applet contains a JTree structure and on selecting a node of the tree an event for the invocation of servlet is occured. I run this code and no exception comes in my browser
java console. But the servlet doent even invoke and show its output.
Here is my applet code:
its init method.
public void init()
{
root = new DefaultMutableTreeNode("root", true);
node1 = new DefaultMutableTreeNode("node 1", true);
node2 = new DefaultMutableTreeNode("node 2" , true);
node3 = new DefaultMutableTreeNode("node 3", true);
root.add(node1);
node1.add(node2);
root.add(node3);
setLayout(new BorderLayout());
tree = new MyJTree(root);
add(new JScrollPane((JTree)tree),"Center");
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
//Listen for when the selection changes.
tree.addTreeSelectionListener(this);
}
public void valueChanged(TreeSelectionEvent e)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf())
{
System.out.println("LEaf");
try
{
URL url = new URL("http://localhost:3265/AppletServlet/treeserv");
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
}
catch(MalformedURLException e5)
{System.out.println(e5.toString());}
catch(IOException e3)
{System.out.println(e3.toString());}
}
else
{
System.out.println("Root");
}
}
My servlet is perfect as it runs normally when i give its own address
in the browser.So i am not presenting its code here. Please send me sample code if possible
Thanks in advance,