object doesn't support error calling Java applet
I just wrote my first Java applet and it appears that I am getting the "Object doesn't support this property or method" error when it returns a message to the calling JavaScript code in my web page.
I have looked at the code for a while with no luck. Perhaps a few extra sets of eyes will see something that I can't. :D
The Java applet is a small, simple socket routine. It sends a text message to a server and waits for a reply message. It returns either the reply or an error message to the JavaScript code which displays it in the textarea.
The <applet> code in the html:
Code:
<APPLET NAME="w2hsocket" CODE="wclient.class" HEIGHT="1" WIDTH="1"></APPLET
The calling code. The error occurs on the highlighted line.
Code:
requestRec = typeStr + commandStr + fileName + " " + custName;
// display request & send it to the FTP app
objForm.output.value += "Sending request: <" + requestRec + ">\n";
replyRec = w2hsocket.sendRequest(requestRec);
objForm.output.value += "Reply received: " + replyRec + "\n";
The Java applet.
Code:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class wclient extends java.applet.Applet
{
private int port = 6711;
private String server = "109.15.1.147";
private Socket socket = null;
private String errMsg;
private String replyRec;
private int statusFailed = 1;
private int statusOK = 0;
public String sendRequest(String requestRec)
{
// connect to the host & send request
if (send2Host(requestRec) == statusFailed)
{
return (errMsg);
}
return (replyRec);
}
// create the socket and connect to the host
// send the request & wait for reply
// close the socket
private int send2Host(String requestRec)
{
try
{
// connect to server
socket = new Socket(server, port);
OutputStream recOut = socket.getOutputStream();
InputStream recIn = socket.getInputStream();
// send the request to server
ObjectOutputStream objrecOut = new ObjectOutputStream(recOut);
objrecOut.writeObject(requestRec);
objrecOut.flush();
// get the reply from the host
ObjectInputStream objrecIn = new ObjectInputStream(recIn);
replyRec = (String)objrecIn.readObject();
// close the connection
socket.close();
}
catch (ClassNotFoundException err)
{
errMsg = err.getMessage();
return (statusFailed);
}
catch (UnknownHostException err)
{
errMsg = err.getMessage();
return (statusFailed);
}
catch (IOException err)
{
errMsg = err.getMessage();
return (statusFailed);
}
return (statusOK);
}
}
Chances are, I'm getting an exception. Am I handling the message correctly in my catch code? Or is there something about the way Java & JavaScript pass strings to each other that I am not aware of?