hey, i am currently in the process of writing a thunderbird extension. to write it i need to be able to link java to javascript using a local server, but i am having serious problems linking them.
all i want the java to do at the moment is to get a random number, pass it to javascript which then puts that number in an alert dialog box all using a local server.

this is the code for the java file which compiles fine:


import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

public class IntelligentSendBackend extends Thread{

Socket c;

static int PORT = 9876;


public IntelligentSendBackend(Socket s) {
c = s;
start();
}

public static void main(String[] a) {
try {
ServerSocket s=new ServerSocket(PORT);
while (true) {
new IntelligentSendBackend(s.accept());
}
}
catch (Exception e) {
}
}

public void run() {
try{

BufferedReader i = new BufferedReader(new
InputStreamReader(c.getInputStream()));
DataOutputStream o = new DataOutputStream(c.getOutputStream());
try {
while (true) {
String s = i.readLine();
if (s.length()<1) break;
if (s.startsWith("GET")) {
StringTokenizer t = new StringTokenizer(s," ");
t.nextToken();
String p = t.nextToken();
if (p.startsWith("/IntelligentSend")) {
String msg =
p.substring(p.indexOf("?msg=")+5, p.length());
o.writeBytes("HTTP/1.0 200OK\nContent-Length: " + msg.length() + "\n\n");

//o.writeBytes(msg.toLowerCase());
o.writeBytes("" + (int)(Math.random()*5));

} else {
o.writeBytes("HTTP/1.0 404 ERROR\n\n\n");
}
}
}
}
catch (Exception e) {
o.writeBytes("HTTP/1.0 404 ERROR\n\n\n");
}
o.close();
}
catch (Exception e) {
}
}
}


this is the javascript code:


function Check(){

var req = new XMLHttpRequest();


req.open("GET", "http://localhost:9876/IntelligentSend?msg=" + msg, true);

req.onload = function parse() {
var response = req.responseText;

}

try {
req.send(null);

}
catch (e) {

}

if(response!= "OK"){
alert(response);
else{
alert("its not working");

}



Can anyone help please??